C Programming MCQ (Multiple Choice Questions)

MCQ on C language

1) Who is known as the father of the C language?

  1. James Rutherford
  2. Dennis Ritchie
  3. Mark Zuckerberg
  4. James A. Gosling
Answer: (B) Dennis Ritchie Explanation: Dennis Ritchie is known as the father of the C language.

2) The C language was developed in ---------?

  1. 1970
  2. 1971
  3. 1972
  4. 1973
Answer: (c) 1972 Explanation: The C language was developed in 1972.

3) The place where the C language developed is ---------?

  1. At sun microsystem
  2. AT & T's Bell Laboratories
  3. Cambridge University
  4. None of the above
Answer: (b) AT & T's Bell laboratories Explanation: The C language was developed in 1972 at AT & T's Bell laboratories in the U.S.A.

4) C language is a -----------.

  1. Low-level language
  2. Medium level language
  3. High-level language
  4. Machine language
Answer: (c) High-level language Explanation: C language is a high-level language.

5) How many keywords are available in the C language?

  1. 27
  2. 29
  3. 30
  4. 32
Answer: (d) 32 Explanation: There are 32 keywords available in the C language.

6) C language uses the ------- to convert the code into machine language.

  1. Compiler
  2. Interpreter
  3. Both compiler and interpreter
  4. None of the above
Answer: (a) compiler Explanation: In the c language, the compiler is used as a translator. The compiler converts high-level language into machine language.

7) Variables in the C program can't start with ------?

  1. Special characters except for the underscore
  2. Numbers
  3. Both a & b
  4. None of the above
Answer: (c) both, a & b. Explanation: In the c program, you can't define a variable name starting with a number or any special character except underscore. A variable name always starts with lower case or upper case alphabets or with an underscore (_).

8) An identifier in the C program can't start with -------?

  1. A digit
  2. An underscore
  3. Lower case alphabets
  4. Upper case alphabets
Answer: (a) A digit Explanation: Same as variables, an identifier also can't start with a digit (number) or with any special characters except for underscore.

9) The range of an integer number in the c language is:

  1. -32767 to 32768
  2. -32768 to 32767
  3. 0 to 255
  4. -3.4e38 to 3.8e38
Answer: (b) -32768 to 32767 Explanation: The range of all variables is pre-defined in the C language. Here is the range of signed and the unsigned integer is given below: Signed integer: -32768 to 32767 Unsigned integer: 0 to 55355 Unsigned character: 0 to 255

10) Lint is a/an ------- in the C language.

  1. C compiler
  2. Interpreter
  3. Analyzing tool
  4. Debugger
Answer: (C) analyzing tool Explanation: Lint is an analyzing tool, which helps the programmer to find out the errors, suspicious action, bugs in the C program. It mainly helps in checking the syntax of the program.

11) What will be the output of the given statement

printf("%d", (a++))
  1. Value of a
  2. Value a+1
  3. Error
  4. None
Answer: (a) value of a Explanation: a++ is a post-increment operator. In the post-increment, firstly, the action is performed on the current value of the variable then increases the value by +1. In this program, firstly, the compiler prints the value of 'a' then increase its value by +1.

12) A constant variable is declared in the C program:

  1. Before the main() function
  2. After the main() function
  3. Anywhere in a new line of the program
  4. Only with other declared variables
Answer: (c) Anywhere in a new line of the program Explanation: The C language allows you to declare a constant variable anywhere in the program, but it should be in the new line or statement.

13) Which loop runs at least one time during the execution of the program?

  1. For loop
  2. While loop
  3. Do-while loop
  4. All of the above
Answer: (c) do-while loop Explanation: In the do-while loop, the compiler executes the do block firstly then checks the condition; if the condition becomes true, then the loop will execute again, otherwise terminated. So even the condition is wrong, the do-while loop will execute one time in the program.

14) What returns the modulus operator in the output?

  1. Dividend
  2. Remainder
  3. As per the user's requirements
  4. Firstly dividend, then the remainder.
Answer: (b) Remainder Explanation: The modulus operator that is denoted by a percentage sign (%) always returns the remainder value in the program.

15) Which function is used to count the number of characters in a string:

  1. len()
  2. strlen()
  3. chlen()
  4. count()
Answer: (b) strlen() Explanation: Strlen() is a function, which is used to determine the length of the string in the C program. This function counts the characters present in the string and gives the result in an integer value, which represents the length of the string in the program.

16) You can declare a string variable by using the --------- keyword in the C program.

  1. str
  2. string
  3. char
  4. char having some size in the array
Answer: (d) char having some size in the array Explanation: The C language does not allow you to use str or string to declare a string variable. It uses the char keyword with some pre-defined size in a square brace to declare a string variable in the program. For example; char ch [10]; Here 'ch' is a variable declared as a string, which will contain a maximum of ten characters in the program.

17) Every C program always required ---------?

  1. A function
  2. An input
  3. An output
  4. None of them
Answer: (a) A function Explanation: Every C program must include a function to be executed successfully. Every c program contains the main function because the compiler starts the compilation process from the main function. The main function is that from where the real program starts.

18) Which type of iterators is used to iterate a vector in the C program?

  1. Forward iterator
  2. Random access iterator
  3. Bi-directional iterator
  4. All of the above
Answer: (d) All of the above Explanation: Iteration is like a pointer variable in the C program, which indicates the value of the variable. The iteration value shows the index value of the variable in the program, and it does affect the value of the variable. So you can use all three types of iterators (which are available in the above options) for the iteration of the vectors in the C program.

19) When a program is successfully terminated, then the value returns to the operating system by the program is -------?

  1. 0
  2. 1
  3. -1
  4. A program does not return any value to the operating system.
Answer: (a) 0 Explanation: When a program is terminated, then it sends a binary value as a report to the operating system. This value may be 0 (zero) or 1 (one). When the program is terminated successfully, then it sends 0, and when the program is terminated with some errors, then it sends 1 to the operating system.

20) A program contains the following code:

main() {
printf("\\nab");
printf("\\bcd");
printf("\\ref");
}
Here, the result of the above program is -----?
  1. abcdef
  2. efacd
  3. acdef
  4. efd
Answer: (d) efd Explanation: In the C language, \n is used for a new line, \b is used for backspace, and \r is used for linefeed in the program. The first statement of the program will print "ab' in the new line. The second statement of the program firstly performs backspace operation then prints the string. So the compiler firstly removes one character, i.e., "b, then prints the string, i.e., "cd.' Thus the output till now is "acd.' The third statement of the program firstly performs linefeed then prints the string. So the compiler moves the cursor to the starting point of the current line. Now it prints the string, i.e., "ef.' So the compiler will override the output. Thus the final output is "efd.'

21) A program contains the following code:

main() {
float n;
double m;
n = 1.1;
m = 1.1;
if (n == m) {
printf("I love coding.");
}
else {
printf("I love testing.");
}
}
Here, the result of the above program is -----?
  1. I love coding.
  2. I love testing
  3. Syntax Error
  4. Logical Error
Answer: (b) I love testing Explanation: The floating-point number is categorized into three parts in the C language, which are
  • Float value
  • Double
  • Long double
The precision of the value of these variables may vary from each other. You can't predict the accurate value of these types of variables. It depends on the number of bytes. That's why values of n and m did not match each other, and else block is executed in this program that prints the statements.

22) A program contains the following code:

void main() {
int n;
char ch;
ch = 'N';
n = ch - 'A';
printf("%d", n);
}
Here, the result of the above program is -----?
  1. 10
  2. 12
  3. 13
  4. Error
Answer: (c) 13 Explanation: When you perform an arithmetic operation on alphabets, then the compile does the action on their ASCII values in the C program. Here, the ASCII value of the character "N' is 78. ASCII value of character "A' is 65. So the subtraction of these characters, i.e., N - A, is 13. Thus the value printed by the compiler is 13.

23) A program contains the following code:

void main() {
int n = 12;
n = !n > 23;
printf("n = %d", n);
}
Here, the result of the above program is ------?
  1. Error
  2. n =12
  3. n = 1
  4. n = 0
Answer: (d) n = 0 Explanation: Whenever there are two or more than two operators in a single statement of the C program, then the compiler uses the precedence of the operators. It executes that operator firstly, whose precedence is higher than others. Here in this program, NPT operator (!) has higher precedence than greater than (>) operator. So !12 is executed first. Result of !12 is 0 (!true becomes false, i.e., 0) and 0 > 23 is also false, so value remains 0. Thus the compiler prints n = 0.

24) A program contains the following code:

void main() {
int n;
n = - -12;
printf("n = %d", n);
}
Here, the result of the above program is ------?
  1. Error
  2. n =12
  3. n = 11
  4. n = -12
Answer: (b) n = 12 Explanation: Here simple math rule is applied in this program. The combination of minus and minus becomes plus. So negative of negative 12 becomes positive 12. Thus the compiler prints n =12. Here one thing to be noted is that you can't use increment (++) or decrement (--) operators with the value. These operators are used only with the variables in the program.

25) A program contains the following code:

void main() {
int n = 7;
printf("%d %d %d %d %d", n++, n--, --n, ++n, n);
}
Here, the result of the above program is ------?
  1. 76786
  2. 67876
  3. 78767
  4. None of them
Answer: (d) None of them Explanation: The correct value is 78677. It is a simple program of increment and decrement operators. In pre-increment and pre-decrement, the value of the variable firstly increases or decreases, then do other operation. While in post-increment and post-decrement, the value of the variable increases or decreases after doing the operation on it. Here, in n++, the compiler print 7 then increases it to 8. In n—the compiler prints 8 then decreases it to 7. In -n firstly, the compiler decreases then prints the value, i.e., 6. In ++n, the compiler increases, then print the value, i.e., 7. In the last, the compiler prints the value of n. So the final result is 78677.

26) A program contains the following code:

# define square(n) n*n
void main() {
int a = 5;
a = a / square(a)
printf("a = %d", a);
}
Here, the result of the above program is ------?
  1. a =5
  2. a = 0
  3. a =0.2
  4. None of them
Answer: (a) a = 5 Explanation: In this program, we define a pre-processor, .i.e., square(n) = n*n So the compiler converts square(n) into n*n. Thus the final equation becomes like this; a = a / a * a Because the division operator and multiply operator have the same priority in the C language, so the compiler performs from left to right direction. So division operation is performed firstly and then multiplication. In division, 5 /5 = 1 and 1 * 5 = 5 Thus the final value of "a' becomes 5.

27) A program contains the following code:

#define clrscr() 123
void main() {
clrscr();
printf("%d", clrscr());
}
Here, the result of the above program is ------?
  1. Compile-time error
  2. 123
  3. No error, but no output.
  4. The program will hang.
Answer: (b) 123 Explanation: Whenever you define a pre-processor in the C program, it passes the contained value separately before the execution process. So the value 123 replaces clrscr() in this program before doing the execution process by the compiler. The statement "123;' is an executable statement, but it does not perform any action. So it does not cause any problem, and the compiler prints the value, i.e., 123. Thus the final result is 123.

28) A program contains the following code:

void main() {
int i;
printf("%d", scanf("%d", &i));
// here, provide value 10 to the variable 'i' as an input.
}
Here, the result of the above program is ------?
  1. 10
  2. 0
  3. 1
  4. Compile-time error
  5. No error, but no output.
Answer: (c) 1 Explanation: scanf function is used to take an input form end-user. It returns a Boolean value as a report to the compiler during the execution of the program. If an input is taken successfully, then it returns 1, otherwise 0. Here in this program, the "i' value is 10, and there will be no problem in scanning it. So the compiler will print 1 in the output.

29) If n = 4.45, then how will you roundup this value that results in 5?

  1. By using ceil(4.45)
  2. By using floor(4.45)
  3. By using roundup(4.45)
  4. By using roundto(4.45)
Answer: (a) By using ceil(4.45) Explanation: There are three functions available to get the round figure of a value in the C program, which are:
  • Ceil function: This function returns the nearest greater than or equal integer value as a result, which is passed with this function.
  • Floor function: This function returns the nearest less than or equal integer value as a result, which is passed with this function.
  • Round function: This function returns the nearest less than integer value as the result if the passing argument is from 0.1 to 0.5. And it returns the nearest less than integer value if the passing argument is from 0.6 to 0.9.
Here, in this program ceil(4.45) = 5 floor(4.45) = 4 So, the first option is the right answer.

30) To get the remainder value in the division of two float values, we use -------- in the C program?

  1. %, i.e., rem = 25.23 % 3.24
  2. modf, i.e., rem = modf(25.23, 3.24)
  3. fmod, i.e., rem = fmod(25.23, 3.24)
  4. Not possible to obtain the remainder value in the division of float values
Answer: (c) fmod Explanation: It is also possible to find out the remainder value from the division of float values in the C program. The C language uses the fmod function to calculate the remainder value of floating-point variables. It works exactly the same as a modulus operator does for integer variables. Here, the result of fmod(25.23, 3.24) is.

31) A real number is treated as --------- in the c program?

  1. A float variable
  2. A double variable
  3. A long variable
  4. None of them.
Answer: (b) A double variable Explanation: When you declare a real number in the C program, then by default, it is treated as a double variable. A double variable is also a floating-point number, but it has a longer precision value in comparison to float value.

32) A program contains the following code:

int main() {
extern int n;
printf("%d", n);
return 0;
}
int n = 45;
Where variable 'n' is declared and defined in this program?
  1. "extern int n' is a declaration statement, and "int n = 45' is the definition statement.
  2. "extern int n' is the definition statement, and "int n = 45' is a declaration statement.
  3. There is no definition statement available in this program, and the statement "int n = 45' is a declaration statement.
  4. The statement "int n = 45' perform as both declaration and definition statement in the program.
Answer: (a) "extern int n" is a declaration statement, and "int n = 45" is the definition statement. Explanation: When we declare a variable in the C program, we tell about the data type of that variable in the declaration, and when we define a variable, then we initialize a value into that variable. In this program, we declare variable n with the extern data type, so it becomes a declaration statement, and another one is a definition statement of the variable.

33) A program contains the following code:

int main() {
extern int n;
n = 45;
printf("%d", n);
return 0;
}
Here, the result of the above program is ------?
  1. 45
  2. None
  3. Error
  4. None of the above
Answer: (c) Error Explanation: The compiler raises a linking error in this program. It tells variable "i' is an undefined symbol in this program. "extern int n' statement says that the value of "n' is not defined in this program. The value of "n' is defined in some other module, and that module is linked with this program. But here, the linker does not find any link of another program with variable "n'. So the compiler generates a linking error.

34) A program contains the following code:

int main() {
extern int n;
printf("%d", n);
return 0;
}
int n = 23;
Here, the result of the above program is ------?
  1. 23
  2. None
  3. Linking Error
  4. None of the above
Answer: (a) 23 Explanation: The statement "extern int i' shows that the value of "n' is taken from some external module of the project. It is not present in the current program. Here the value of variable "n' is defined outside of the program, and it works as a local variable for this program. The compiler will print the value 23 because, in the conflict of a local and global variable, the priority goes to the local variable.

35) A program contains the following code:

int main() {
int n = 8;
for(; scanf("%s, & n); printf("%d", n));
return 0;
}
How many times for loop will be iterated in this program?
  1. 8 times
  2. 1 time
  3. Infinite times
  4. The program will execute with no error, but the loop will not iterate
  5. Error
Answer: (c) Infinite times Explanation: In this for loop statement, the scanf function asks for input and the printf function prints the input value. This for loop is going to run infinite times because the compiler asks for input from the end-user, and every time end-user will provide the input. So the scanf function always returns 1, and it becomes true. Thus the condition becomes true every time, and the loop goes into an infinite state.

36) A program contains the following code:

#include
int main() {
abc();
return 0;
}
void abc() {
printf("Hey..!! My name is Jessica");
}
Find out the error, if any, available in this program?
  1. No error.
  2. Function abc() will not invoke.
  3. Function abc() is called, but it is not defined.
  4. None of the above.
Answer: (c) Function abc() is called, but it is not defined Explanation: It is necessary to define a function (i.e., created by the user itself) before the main function. The function definition tells the compiler that the given function also exists in the program; otherwise, the compiler raises an error at the time of compilation. To figure out this problem, you need to add a function prototype of the abc() function before the main() function, i.e., void abc(); OR (2nd way) define the abc() function before the main.

37) What is the difference between structure and union in the C program?

  1. Structure store different type variables, while union stores the same type variables.
  2. The structure uses different memory locations, while the union uses the same memory location for their elements.
  3. The structure can pass by value to the function, while the union can't pass by value to the function.
  4. None of the above
Answer: (b) The structure uses different memory locations, while the union uses the same memory location for their elements. Explanation: Structure and union are mostly the same in the C language. A union stores each type of variable, and all variables have the same memory location, but only one member can be accessed at a time. It provides better use of memory in the program, while in the structure, every member has a separate memory location in the program.

38) A program contains the following code:

int main() {
static int n;
n = 5;
printf("%d", n--);
if (n)
main();
return 0;
}
Here, the result of the above program is ------?
  1. 54321
  2. Prints 5 infinite times
  3. None
  4. Compile-time error
Answer: (a) 54321 Explanation: When you declare a variable with the static keyword, then the changes made in the value of the static variable is retained in the program. It also happens between the function calls. In this program, the main() function is also treated as a normal function, so it will call until the value of n becomes 0. Thus the compiler prints 54321.

39) A program contains the following code:

int main() {
char not;
not = !45;
printf("%d", not);
return 0;
}
Here, the result of the above program is ------?
  1. 45
  2. 54
  3. 0
  4. Garbage value
  5. None of the above
Answer: (c) 0 Explanation: The not operator (!) is a logical operator, which returns a Boolean value, i.e., 0 or 1 in the program. In the C language, 0 is considered as FALSE, and every non-zero value is considered as TRUE. So !45 is considered as FALSE by the compiler, and it prints 0 in the result of this program.

40) A program contains the following code:

int main() {
register n;
char ch[] = "Age";
n = 23;
printf("%s %d", ch, n);
return 0;
}
Here, the result of the above program is ------?
  1. Age 23
  2. Age garbage value
  3. Error
  4. None of the above
Answer: (a) Age 23 Explanation: In the C language, the register variable is also treated as a normal variable, so it does not affect the program. The "register' keyword describes that the given variable will use a very small memory size in the program. So, the compiler treat it as a normal program and prints Age 23 as output.

41) A program contains the following code:

int main() {
int n1, n2;
n1 = 20;
n2 = 25;
printf("%d", n1+++n2);
return 0;
}
Here, the result of the above program is ------?
  1. 44
  2. 45
  3. 46
  4. Compile-time error
Answer: (b) 45 Explanation: The compiler treated the operation "n1+++n2' as "(n1++) + n2' in this program. The first two operators are used for post-increment; remain single plus operator, which is used for addition. It happens because of the precedence of operators in the program. Thus the compiler firstly does the addition then does the increment (because it is post-increment). It prints the addition result, i.e., 45.

42) A program contains the following code:

int demo(int i) {
return i++;
}
int main() {
int n;
n = demo(45);
printf("%d", --n);
return 0;
}
Here, the result of the above program is ------?
  1. 44
  2. 45
  3. 46
  4. None of the above
Answer: (a) 44 Explanation: The "return i++' statement returns the value of "i' in the program. So the value of "i' remains the same in the main function. The print statement prints the value of "n' after pre-decrement. So the compiler prints 44 in the result of this program.

43) A program contains the following code:

int main() {
int x = x++, y = y++, z = z++;
printf("%d %d %d", x, y, z);
return 0;
}
Here, the result of the above program is ------?
  1. Garbage value
  2. Error
  3. 0 0 0
  4. 1 1 1
Answer: (a) Garbage value Explanation: The use of post-increment in the variable declaration statement is valid here because an identifier is available in this statement, which can use the program codes at the point of the declaration. The variables x, y,z are automatic variables, so they will contain some garbage values if you do not define any value for them. Thus the compiler prints garbage value as the result of this program.

44) A program contains the following code:

int main() {
static int x = x++, y = y++, z = z++;
printf("%d %d %d", x, y, z);
return 0;
}
Here, the result of the above program is ------?
  1. Garbage value
  2. Error
  3. 0 0 0
  4. 1 1 1
Answer: (d) 1 1 1 Explanation: The variables are declared with the static keyword in the C program; by default, they are initialized with zero. So the normal value of the variable x, y, and z is zero in this program. In the declaration statement, a post-decrement operation is also performed, so the value of these variables are incremented by +1. Thus the compiler prints 1 1 1 as the result of this program.

45) A program contains the following code:

int main() {
char ch[] = "%d";
ch[1] = 'a';
printf(ch, 65);
return 0;
}
Here, the result of the above program is ------?
  1. A
  2. a 65
  3. A
  4. 65
  5. Error
Answer: (c) A Explanation: The variable "ch' gets converted into %c from %d because it stores the character "a' from the initialization statement. And the printf function takes it as a string format and assumes 65 as an ASCII value. ASCII value of 65 is "A'; thus, the compiler prints the character "A' as the result of this program.

46) To print the '\n' on the screen, which of the following print statement is right?

  1. printf("\n')
  2. printf("\n')
  3. printf("\\n')
  4. echo "\\n'
Answer: (c) printf("\\n") Explanation: You can print the special character '\n' with the help of double back-slashes in the print statement of the program.

47) A program contains the following code:

int main() {
char *ch;
ch = "%d";
ch++;
ch++;
printf(ch - 2, 23);
return 0;
}
Here, the result of the above program is ------?
  1. Compile-time error
  2. 23
  3. 21
  4. 25
  5. None
Answer: (b) 23 Explanation: Here, "ch' is a pointer variable in this program. This pointer variable is pointed to the %d and then incremented two times. Since %d is not changed, so the printf function takes it in the integer format. In the printf statement, variable "ch' is again decremented by -2, so the same value is printed by the compiler. Thus the compiler prints 23 as the result of this program.

48) A program contains the following code:

int main() {
int n1, n2;
n1 = 065;
n2 = 27;
printf("%d %d", n1, n2);
return 0;
}
Here, the result of the above program is ------?
  1. 065 27
  2. 65 27
  3. 53 27
  4. 53 33
Answer: (c) 53 27 Explanation: The value of variable "n1' is an octal value. So the compiler automatically changes it into a decimal number at the time of printing. The compiler changes because the printf statement has identifier %d, which represents integer numbers in the program. The decimal of 065 is 53. The value of n2 will not change because the compiler takes normal values as a decimal number. Thus the compiler prints 53 27 as the result of this program.

49) A program contains the following code:

int main() {
char *ch;
ch = "John"
"Doe";
printf("%s", ch);
return 0;
}
Here, the result of the above program is ------?
  1. Syntax Error
  2. John Doe
  3. John Doe
  4. John
  5. None of the above
Answer: (b) John Doe Explanation: In the C language, a single statement is considered until the compiler didn't receive a semicolon. So variable 'ch' has a string value, i.e., John Doe. The compiler is considered as a new line when you use \n in the program. But there is no \n in the string declaration, so it comes in a single line in the output.

50) A program contains the following code:

int main() {
int n;
for(n = 1; n < 25; n += 3) {
++n;
n++;
printf("%d", n);
n++;
}
return 0;
}
Here, the result of the above program is ------?
  1. 2 7 12 17 22
  2. 3 8 13 18 23
  3. 3 7 11 15 19 23
  4. 3 9 15 21
Answer: (d) 3 9 15 21 Explanation: It is a normal C program in which for loop and pre and post-increment operators are used. Here is this program, for loop will iterate till the value of n is less than 25. Thus the compiler prints 3 9 15 21 as the result of this program.

51) You can swap the value of two variables by using -----------?

  1. temp = a; a = b; b = temp;
  2. a = a + b; b = a - b; a = a - b;
  3. Both a & b.
  4. None of the above
Answer: (c) Both a & b. Explanation: There are two methods to swap the values of the variable in the C program. The first one is by using the 3rd variable, and the second one is without using the 3rd variable. Option (a) is with using the 3rd variable, i.e., temp. Option (b) is without using the 3rd variable. After the successful operation of any option between them, the value of the variable "a' and "b' will be swapped successfully.

52) A program contains the following code:

int main() {
char s1 [23], s2 [25];
s1 = "Lara";
s2 = "Croft";
printf("%s", strcpy(s2, strcat(s1, s2)));
return 0;
}
Here, the result of the above program is ------?
  1. Lara
  2. Croft
  3. Lara Croft
  4. Croft Lara
  5. Error
Answer: (c) Lara Croft Explanation: It is a program of string concatenation and copying a string. The "strcat' function is used for the concatenation of the string, and the "strcpy' function is used to copy the string. In the strcart function, the value of the variable s2 appends in variable s1. In the strcpy function, the resultant value of the strcat function is copied in variable s2. Thus the compiler prints the string "Lara Croft' as the result of this program.

53) A program contains the following code:

int main() {
char s1 [23], s2 [25];
s1 = "Lara";
s2 = "Lara";
if( s1 == s2)
printf("Equal String.")
else
printf("Unequal String.');
return 0;
}
Here, the result of the above program is ------?
  1. Equal String
  2. Unequal String
  3. Compile-time error
  4. None of the above
Answer: (b) Unequal String Explanation: For comparison of the string variables, we have the strcmp() function available in the C language. strcmp() compares string value and produces the result in the Boolean format. But when we compare string variables with the help of a comparison operator, then it compares the address of those variables instead of comparing their values. The address of each variable is different; thus, the compiler prints the unequal string as the result of this program.

54) A program contains the following code:

int main() {
float n;
n = 20.25639;
printf("%2.1f", n);
return 0;
}
Here, the result of the above program is ------?
  1. Syntax Error
  2. 25639
  3. 2
  4. 3
Answer: (d) 20.3 Explanation: We have a float type variable, i.e., n, and its value is 20.25639 in this program. In the print statement, we have a precision specifier, i.e., .1f, which tells that the print statement prints only one digit after the decimal point. The first digit after the decimal is auto-incremented by +1 if the second digit after the decimal point is equal or greater than 5. Thus the compiler prints 20.3 as the result of this program.

55) A program contains the following code:

#include
#define cube(a) (a*a*a)
int main() {
int n1 = 4, n2 ;
n2 = cube(n1++);
printf("%d %d", n1, n2);
return 0;
}
Here, the result of the above program is ------?
  1. 5 5
  2. 5 64
  3. 4 64
  4. 7 64
  5. Error
Answer: (d) 5 64 Explanation: In this program, cube(a) is defined as a*a*a with the help of a pre-processor, which means the cube(a) will be replaced with a*a*a in this program. So the compiler replaces "a' with "n1'; thus, the statement becomes like this: n1++ * n1++ * n1++ in this way, the value of n1 is multiplied three times, and after multiplication, it is also incremented three times. Thus the value of n2 is: 4 * 4 * 4 = 64 And the incremented value of n1 is = 7 Thus the compiler prints 7 64 as the result of this program.

56) Which data type variable uses %i in the C program:

  1. Integer variable
  2. float variable
  3. string variable
  4. All of the above
Answer: (a) integer variable Explanation: %i is also used for an integer variable. An integer variable has two identifiers, i.e., %d and %i in the C language; you can use any of them in the C program.

57) A program contains the following code:

#include
int main() {
char *ch ;
ch = "ABC";
while(*ch)
printf("%c", *ch++);
return 0;
}
Here, the result of the above program is ------?
  1. ABC ABC ABC… continues
  2. ABC BCD CDE… continues
  3. Some addresses will be printed till the loop is true.
  4. Compile-time error
  5. None of the above
Answer: (a) ABC ABC ABC… continues Explanation: "ch' is a pointer variable in this program. Hence the print statement prints the value, i.e., "ABC,' then increment the address of the variable by +1 until the value of the variable "ch' does not become zero. Thus the compiler prints ABC till the loop is true as the result of this program.

58) A program contains the following code:

#include
int main() {
int n1 = 4, 5, 6 ;
printf("%d", n1);
return 0;
}
Here, the result of the above program is ------?
  1. 4
  2. 5
  3. 6
  4. None
  5. Compile-time error
Answer: (a) 4 Explanation: The associativity of the comma operator in left to right in the C language and the precedence assignment operator is higher than the comma operator. So the compiler will assume the declaration statement as follows: int (n1 = 4), 5, 6; Thus the value 4 is assigned to the variable n1, and the compiler prints 4 as the result of this program.

59) In which way the recursive functions are executed?

  1. In a parallel order
  2. FIFO order (First In First Out)
  3. LIFO order (Last In First Out)
  4. Random order
Answer: (c) LIFO order (Last In First Out) Explanation: In each function call, entry is created in the form of a stack, so they perform in LIFO (Last In First Out) manner.

60) What is the default mechanism of parameter passing in the c program?

  1. Call by value
  2. Call by reference
  3. Call by value's result.
  4. All of the above
Answer: (a) Call by value Explanation: By default, the compiler uses call by value mechanism in the C language.