Podcast
Questions and Answers
What was the original goal of the American National Standards Institute (ANSI) committee established in 1983 related to the C programming language?
What was the original goal of the American National Standards Institute (ANSI) committee established in 1983 related to the C programming language?
Which programming language was UNIX primarily written in?
Which programming language was UNIX primarily written in?
What makes UNIX one of the first portable operating systems?
What makes UNIX one of the first portable operating systems?
Who originally designed the C programming language for use with UNIX on DEC PDP-11 computers?
Who originally designed the C programming language for use with UNIX on DEC PDP-11 computers?
Signup and view all the answers
Which book was the first publication about the C programming language, authored by Brian Kernighan and Dennis Ritchie?
Which book was the first publication about the C programming language, authored by Brian Kernighan and Dennis Ritchie?
Signup and view all the answers
What was one of the earlier forms of the C language before it evolved from B?
What was one of the earlier forms of the C language before it evolved from B?
Signup and view all the answers
What is the purpose of local declarations in a C program?
What is the purpose of local declarations in a C program?
Signup and view all the answers
Which of the following statements is considered part of a C program?
Which of the following statements is considered part of a C program?
Signup and view all the answers
In C programming, what is the purpose of user-defined functions?
In C programming, what is the purpose of user-defined functions?
Signup and view all the answers
What is the role of the return function in C programs?
What is the role of the return function in C programs?
Signup and view all the answers
Why must every file containing a C program be saved with a '.c' extension?
Why must every file containing a C program be saved with a '.c' extension?
Signup and view all the answers
What is the purpose of the linker in C programming?
What is the purpose of the linker in C programming?
Signup and view all the answers
Which component loads the executable file into RAM during program execution?
Which component loads the executable file into RAM during program execution?
Signup and view all the answers
What does the Instruction Register do during program execution?
What does the Instruction Register do during program execution?
Signup and view all the answers
'Program Counter' in C programming is responsible for:
'Program Counter' in C programming is responsible for:
Signup and view all the answers
What does the Accumulator store during program execution in C programming?
What does the Accumulator store during program execution in C programming?
Signup and view all the answers
What is the name of the recognized standard for C language established by ANSI?
What is the name of the recognized standard for C language established by ANSI?
Signup and view all the answers
Which organization established a standard for C similar to ANSI C?
Which organization established a standard for C similar to ANSI C?
Signup and view all the answers
What is the primary advantage of using C for writing programs?
What is the primary advantage of using C for writing programs?
Signup and view all the answers
Which section of a C program includes program's name, date, and description?
Which section of a C program includes program's name, date, and description?
Signup and view all the answers
What purpose does the preprocessor section serve in a C program?
What purpose does the preprocessor section serve in a C program?
Signup and view all the answers
Which keyword is used to declare constants in the define section of a C program?
Which keyword is used to declare constants in the define section of a C program?
Signup and view all the answers
What is the purpose of the main function in a C program?
What is the purpose of the main function in a C program?
Signup and view all the answers
'void main()' versus 'int main()' in C programming primarily differs in:
'void main()' versus 'int main()' in C programming primarily differs in:
Signup and view all the answers
Why is C considered well-suited for writing both system and application software?
Why is C considered well-suited for writing both system and application software?
Signup and view all the answers
What is the output of the following code snippet?
#include int main() {
int a, b, sum;
printf("Enter two no: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
return(0);
}
Given Input: 3 7
What is the output of the following code snippet?
#include int main() {
int a, b, sum;
printf("Enter two no: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
return(0);
}
Given Input: 3 7
Signup and view all the answers
What does the C function 'ceil(number)' do?
What does the C function 'ceil(number)' do?
Signup and view all the answers
Which of the following is NOT a C keyword?
Which of the following is NOT a C keyword?
Signup and view all the answers
What does the 'pow(base, exponent)' function do in C?
What does the 'pow(base, exponent)' function do in C?
Signup and view all the answers
In C programming, what do identifiers refer to?
In C programming, what do identifiers refer to?
Signup and view all the answers
What is an essential requirement for declaring identifiers in C programming?
What is an essential requirement for declaring identifiers in C programming?
Signup and view all the answers
What is the purpose of assigning values to variables in a C program?
What is the purpose of assigning values to variables in a C program?
Signup and view all the answers
'sizeof' is an example of which of the following in C programming?
'sizeof' is an example of which of the following in C programming?
Signup and view all the answers
'int_amt=(prt)/100;' in C programming is an example of what?
'int_amt=(prt)/100;' in C programming is an example of what?
Signup and view all the answers
Which function in C programming rounds down a given number?
Which function in C programming rounds down a given number?
Signup and view all the answers
Which type of variable retains its value between multiple function calls?
Which type of variable retains its value between multiple function calls?
Signup and view all the answers
What is the default visibility scope of automatic variables in C?
What is the default visibility scope of automatic variables in C?
Signup and view all the answers
In C, where must global variables be declared?
In C, where must global variables be declared?
Signup and view all the answers
What is the purpose of the static keyword when declaring a variable in C?
What is the purpose of the static keyword when declaring a variable in C?
Signup and view all the answers
Which storage class is associated with automatic variables in C?
Which storage class is associated with automatic variables in C?
Signup and view all the answers
What is the default lifetime of static variables in C?
What is the default lifetime of static variables in C?
Signup and view all the answers
Which symbol is not allowed to start a variable name in C?
Which symbol is not allowed to start a variable name in C?
Signup and view all the answers
'int long' is an invalid variable name in C because:
'int long' is an invalid variable name in C because:
Signup and view all the answers
'extern int x=10;' declares an external variable with an initial value. Why might this declaration cause issues?
'extern int x=10;' declares an external variable with an initial value. Why might this declaration cause issues?
Signup and view all the answers
Which data type is used to store the address of a variable in C?
Which data type is used to store the address of a variable in C?
Signup and view all the answers
What is the range of an unsigned char data type in C?
What is the range of an unsigned char data type in C?
Signup and view all the answers
Which of the following is an example of a derived data type in C?
Which of the following is an example of a derived data type in C?
Signup and view all the answers
What is the purpose of using typedef in C?
What is the purpose of using typedef in C?
Signup and view all the answers
What do escape sequences represent in C?
What do escape sequences represent in C?
Signup and view all the answers
Which type of constant allows for increasing the storage range in C?
Which type of constant allows for increasing the storage range in C?
Signup and view all the answers
'I am a little boy' would be classified as:
'I am a little boy' would be classified as:
Signup and view all the answers
'typedef int Integer;' statement creates a synonym for which data type?
'typedef int Integer;' statement creates a synonym for which data type?
Signup and view all the answers
Which storage class in C allows variables to hold their value between multiple function calls?
Which storage class in C allows variables to hold their value between multiple function calls?
Signup and view all the answers
In C, which storage class allows variables to be stored in the CPU registers?
In C, which storage class allows variables to be stored in the CPU registers?
Signup and view all the answers
What happens if you try to dereference a register variable in C?
What happens if you try to dereference a register variable in C?
Signup and view all the answers
What does the extern storage class declaration indicate in C?
What does the extern storage class declaration indicate in C?
Signup and view all the answers
What does the compiler do if an extern variable in C is not initialized within the program?
What does the compiler do if an extern variable in C is not initialized within the program?
Signup and view all the answers
Study Notes
History of C
- The C language was first proposed in 1972 by Dennis M. Ritchie at Bell Laboratories, USA.
- In 1983, the American National Standards Institute (ANSI) established a committee to standardize the definition of C, resulting in ANSI C.
- ANSI C is the recognized standard for the language, grammar, and core set of libraries.
Characteristics of C
- C is a robust language with a rich set of built-in functions, data types, and operators.
- Programs written in C are efficient due to the availability of several data types and operators.
- C is a highly portable language, allowing code written on one machine to be easily moved to another.
- C supports low-level features like bit-level programming and direct access to memory using pointers.
Basic Structure of a C Program
- A C program consists of several sections, including:
- Documentation section (includes comments and program description)
- Preprocessor section (includes header files and library links)
- Definition section (includes constants and macros)
- Global declaration section (includes global variables and functions)
- Main function (the entry point of the program)
- User-defined functions (custom functions written by the programmer)
Program Execution
- When a C program is compiled and executed, the compiler generates several files, including:
- Source file (with a .c extension)
- Object file (with a .obj extension)
- Executable file (with a .exe extension)
- The program is executed in the following steps:
- The loader loads the executable file into RAM and informs the CPU of the starting point.
- The CPU executes the program, using the Instruction Register and Program Counter.
C Math Functions
- C provides several math functions, including:
- ceil() (rounds up a number)
- floor() (rounds down a number)
- sqrt() (returns the square root of a number)
- pow() (returns the power of a number)
- abs() (returns the absolute value of a number)
C Tokens
- Tokens are the individual units of a C program, including:
- Keywords (reserved words with specific meanings)
- Identifiers (names of variables, functions, and arrays)
- Constants (numeric, character, or string values)
- Operators (symbols used for arithmetic, comparison, and logical operations)
- Punctuators (symbols used for grouping and separating tokens)
Keywords
- Keywords are reserved words in C, including:
- auto
- double
- int
- struct
- break
- else
- long
- switch
- ...
Identifiers
- Identifiers are names of variables, functions, and arrays, and must follow certain rules:
- Can be named from a combination of A-Z, a-z, 0-9, and _
- First character must be an alphabet or underscore
- Must not be a keyword
- Can be up to 31 characters long
Data Types
- C provides several data types, including:
- int
- float
- char
- double
- long
- short
- unsigned
- ...
Variables
- Variables are named storage locations that can hold different values, and can be:
- Local (declared inside a function or block)
- Global (declared outside a function or block)
- Static (retains its value between multiple function calls)
- Automatic (allocated memory automatically at runtime)
- External (shared across multiple C source files)
Storage Classes
- Storage classes in C determine the lifetime, visibility, memory location, and initial value of a variable, including:
- Automatic
- External
- Static
- Register### C Data Types
- C supports four classes of data types: basic, derived, user-defined, and pointer data types.
Basic Data Types
- Basic data types support arithmetic operations such as addition and subtraction.
- Examples:
int a, b;
,char c;
- Storage size and range of basic data types:
-
Unsigned char
: 8 bits, 0 to 255 -
Char
: 8 bits, -128 to 127 -
Short int
: 16 bits, -32768 to 32767 -
Unsigned int
: 32 bits, 0 to 4294967295 -
Int
: 32 bits, -2147483648 to 2147483648 -
Unsigned long
: 32 bits, 0 to 4294967295 -
Enum
: 16 bits, -2147483648 to 2147483648 -
Long
: 32 bits, -2147483648 to 2147483648 -
Float
: 32 bits, 3.4e-38 to 3.4e38 -
Double
: 64 bits, 1.7e-308 to 1.7e308 -
Long double
: 80 bits, 3.4e-4932 to 1.1e4932
-
Derived Data Types
- Derived data types store a set of data values.
- Examples: arrays and structures.
User-Defined Data Types
- C provides a facility called
typedef
for creating new data type names defined by the user. - Example:
typedef int Integer;
makesInteger
a synonym ofint
.
Pointer Data Types
- Pointer data types store the address of a variable.
Constants
- A constant is a quantity that does not vary during the execution of a program.
- Two types of constants: numeric and character constants.
Numeric Constants
- Examples:
786
,-127
,1234567899L
(long constant) - Unsigned constants:
123456789u
(unsigned constant),1234567891ul
(unsigned long constant) - Advantage of declaring an unsigned constant: increases the range of storage.
- Floating-point constants:
123.4
,1e-2
,1.4E-4
Character Constants
- A character constant is written as one character within single quotes, e.g.
'a'
. - Escape sequences:
\a
(alert),\b
(backspace),\f
(form feed),\n
(new line),\r
(carriage return),\t
(horizontal tab),\v
(vertical tab)
String Constants
- A string constant is a sequence of zero or more characters surrounded by a double quote, e.g.
" I am a little boy"
. - Quotes are not part of the string.
Enumeration Constants
- An enumeration constant is a list of constant integer values, e.g.
enum color { RED, Green, BLUE }
. - The first name in the enum has the value 0, and the next 1, and so on unless explicit values are specified.
Variables
-
auto
variables: default initial value is garbage. -
static
variables:- Hold their value between multiple function calls.
- Visible only to the function or block in which they are defined.
- Can be declared many times but can be assigned at only one time.
- Default initial value of static integral variables is 0 otherwise null.
-
register
variables:- Allocated memory into the CPU registers.
- Can not be dereferenced (i.e., can not use & operator).
- Access time is faster than automatic variables.
- Initial default value of register local variables is 0.
- Can store pointers into the register.
-
extern
variables:- Used to tell the compiler that the variable is declared with an external linkage elsewhere in the program.
- Not allocated any memory.
- Default initial value of external integral type is 0 otherwise null.
- Can only initialize the extern variable globally.
- Can be declared many times but can be initialized at only once.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Explore the evolution and milestones of the C programming language, which originated at Bell Laboratories in 1972. Learn about the standardization efforts by ANSI and its association with UNIX.