Lec-4 Flashcards
What are the sizes of common data types in C?
char: 1 byte
int: 4 bytes
float: 4 bytes
double: 8 bytes
long: 8 bytes
What are the rules for identifiers in C?
Identifiers consist of A-Z, a-z, 0-9, and underscore, are case-sensitive, cannot start with a number, and cannot be a keyword.
What are best practices for naming identifiers?
Use meaningful names, limit to 31 characters, use lowercase for single syllables, and use underscore or camel case for multiple syllables.
What does the scanf() function do?
Reads input from standard input, uses format specifiers, and requires the address operator (&).
What does the printf() function do?
Outputs formatted text, uses conversion specifiers, and allows direct calculations within output.
What are some common format specifiers in C?
%c: Characters
%f: Floats
%lf: Doubles
%d: Integers
%s: Strings
How are constant variables declared in C?
Declared with ‘const’ keyword, must be initialized during declaration, and cannot be modified after initialization.
What is the purpose of the #define preprocessor directive?
Creates symbolic constants, replaces identifiers before compilation, and provides global constant definitions.
What are the advantages of using constants in C programming?
Improve code readability, eliminate ‘magic numbers’, and facilitate easier program maintenance.