C 2marks - Unit1 & 2
C 2marks - Unit1 & 2
o Answer:
1. Preprocessor directives.
3. main() function.
4. Define a constant in C.
o Answer: A constant is a fixed value that cannot be changed during the execution of a
program. It can be defined using the const keyword or #define preprocessor
directive.
o Answer: Keywords are reserved words in C that have predefined meanings and
cannot be used for other purposes like variable names. Examples include int, return,
if.
o Answer: Operator associativity defines the direction in which operators of the same
precedence are evaluated. For example, + and - are left-associative, so they are
evaluated from left to right.
#define PI 3.14
o Answer:
// statements
o Answer:
while (condition) {
}
17. Write syntax for “do-while loop”
o Answer:
do {
} while (condition);
o Answer: A while loop checks the condition before executing the loop body, whereas
a do-while loop executes the body first and checks the condition afterward, ensuring
the loop runs at least once.
1. What is an array in C?
o Answer:
o Answer: A two-dimensional array is declared as: int arr[3][4];, where 3 is the number
of rows and 4 is the number of columns.
o Answer: The syntax to access elements in a 2D array is: arr[i][j], where i is the row
index and j is the column index.
o Answer: The strlen() function returns the length of a string, excluding the null
terminator (\0).
o Answer: You can concatenate two strings using the strcat() function. Example:
strcat(str1, str2);
o Answer: You can copy one string to another using the strcpy() function. Example:
char dest[20];
strcpy(dest, src);
o Answer: Selection sort is a sorting algorithm that repeatedly selects the smallest (or
largest) element from the unsorted part of the array and swaps it with the first
element of the unsorted part.