Podcast
Questions and Answers
What is the maximum value that an 'int' type variable can hold in C?
What is the maximum value that an 'int' type variable can hold in C?
- -2,147,483,648
- 1,073,741,823
- 2,147,483,647 (correct)
- 4,294,967,295
Which of these statements about variable names in C is incorrect?
Which of these statements about variable names in C is incorrect?
- Underscores are allowed in variable names.
- Uppercase letters can be used in variable names.
- Variable names must not contain spaces.
- Variable names can start with a digit. (correct)
Which C data type is typically used to store a single character?
Which C data type is typically used to store a single character?
- char (correct)
- float
- short
- int
What is the purpose of using 'unsigned' with a variable type in C?
What is the purpose of using 'unsigned' with a variable type in C?
What is the bit size of a 'float' data type in C?
What is the bit size of a 'float' data type in C?
Which preprocessor directive is mandatory for the functioning of a C program?
Which preprocessor directive is mandatory for the functioning of a C program?
What is the purpose of the #undef directive in C?
What is the purpose of the #undef directive in C?
Which of the following correctly indicates the structure of the main() function in C?
Which of the following correctly indicates the structure of the main() function in C?
Where must all variables be declared in a C program?
Where must all variables be declared in a C program?
Which of the following is considered an integer constant in C?
Which of the following is considered an integer constant in C?
What is the function of the #ifdef directive?
What is the function of the #ifdef directive?
Which data type is NOT represented by a constant in C?
Which data type is NOT represented by a constant in C?
What character must end each instruction within the main() function?
What character must end each instruction within the main() function?
What does the declaration 'float zx, zy;' indicate?
What does the declaration 'float zx, zy;' indicate?
Which of the following correctly initializes an integer variable in C?
Which of the following correctly initializes an integer variable in C?
In C, what is the result of the operation '5 % 2'?
In C, what is the result of the operation '5 % 2'?
What does the statement 'a = b + 1;' illustrate?
What does the statement 'a = b + 1;' illustrate?
Which of the following variable types allows for negative values in C?
Which of the following variable types allows for negative values in C?
What will the following statement 'j = i++;' accomplish in C if 'int i = 1;'?
What will the following statement 'j = i++;' accomplish in C if 'int i = 1;'?
What will the expression 'int i = 1, j;' followed by 'j = ++i;' result in?
What will the expression 'int i = 1, j;' followed by 'j = ++i;' result in?
What does the declaration 'char zz = 'a';' specify?
What does the declaration 'char zz = 'a';' specify?
Study Notes
Integers for Boolean Tests
- Integers are used for boolean tests in C:
- 0 is equivalent to false
- Any non-zero value is considered true
Variable Names in C
- C differentiates between uppercase and lowercase letters.
- Variable names are written in lowercase for clarity.
- Uppercase letters are used for symbolic constants defined by
#define
. - Variable names must start with a letter and cannot contain spaces.
- Only an underscore is allowed as a special character.
- Reserved keywords like
while
,if
,case
, and function names cannot be used as variable names.
Variable Declarations in C
- To declare a variable, prefix its name with its data type.
- There are 6 basic data types in C:
- char: Character, occupies one byte (8 bits), with a range of -128 to 127.
- short: Integer, occupies two bytes, with a range of -32,768 to 32,767.
- int: Integer, occupies four bytes, with a range of -2,147,483,648 to 2,147,483,647.
- long: Integer, occupies 8 bytes, with a range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
- float: Real number, occupies four bytes, with a range of approximately -10^38 to 10^38.
- double: Real number, occupies eight bytes, with a range of approximately -10^308 to 10^308.
- Each type can be prefixed with
unsigned
, forcing the variable to hold only positive values.
Preprocessor Directives
#include
: Allows the use of functions likeprintf()
andscanf()
.#include <math.h>
: Allows the use of mathematical functions.#define PI 3.14159
: Defines the constantPI
.#undef PI
: Undefines the constantPI
from this point onwards.#ifdef PI
: Compiles instructions 1 ifPI
is defined, otherwise compiles instructions 2.#else
: Provides alternative instructions ifPI
is not defined.#endif
: Ends the conditional compilation block.
General Structure of a C Program
- Only one preprocessor directive is mandatory:
#include <stdio.h>
. - This directive enables functions like
printf()
for screen output andscanf()
for keyboard input.
The main()
Function in C
- The
main()
function is the starting point of every C program. - It's defined using the syntax:
main() { ... }
. - Instructions within the
main()
function are enclosed in curly braces and end with semicolons. - All variables must be declared before they can be used within
main()
.
Examples of Variable Declarations in C
int a;
: Declares an integer variable nameda
.int z = 4;
: Declares an integer variable namedz
and initializes it with the value 4.unsigned int x;
: Declares an unsigned integer variable namedx
.float zx, zy;
: Declares two float variables namedzx
andzy
.float zx = 15.15;
: Declares a float variable namedzx
and initializes it with the value 15.15.double z;
: Declares a double-precision real number variable namedz
.char zz;
: Declares a character variable namedzz
.char zz = 'a';
: Declares a character variable namedzz
and initializes it with the character 'a'.
Basic Operators in C
- The assignment operator (
=
) assigns the value on the right-hand side to the variable on the left-hand side. - Basic arithmetic operators:
+
: Addition-
: Subtraction*
: Multiplication/
: Division%
: Modulo (remainder of division)
Advanced Operators in C
++
: Increments a variable by 1.--
: Decrements a variable by 1.- These operators are not used with floating-point numbers.
i++
: Incrementsi
after using its current value.++i
: Incrementsi
before using its value.'a' + 1
: Valid operation in C, it yields the next character in the ASCII sequence after 'a'.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Test your knowledge of fundamental C programming concepts, including boolean tests with integers, variable naming conventions, and variable declarations. This quiz covers important rules and data types essential for writing clear and correct C code.