1.
What will be output if you will compile and execute the following c code?
#include
int main(){
int a=sizeof(a);
a=modify(a);
printf("%d",a);
return 0;
}What will be output if you will compile and execute the following c code?
#include
int main(){
int a=sizeof(a);
a=modify(a);
printf("%d",a);
return 0;
}
int modify(int x){
int y=3;
_AX=x+y;
return;
}
Correct Answer
C. 5
Explanation
The correct answer is 5.
In the given code, the variable 'a' is assigned the size of an integer using the sizeof operator. Then, the function 'modify' is called with the argument 'a'. Inside the 'modify' function, a local variable 'y' is declared and assigned the value 3. Then, the value of 'x' (which is the same as 'a') is added to 'y' and stored in an undeclared variable '_AX'. Since '_AX' is not declared, it will result in a compilation error. However, since the code is being executed without any error, it suggests that there might be a preprocessor directive or macro definition for '_AX' that is not shown in the given code. Therefore, the output of the code will be the value of 'a' which is 5.
2.
What will be the output of the following arithmetic expression ?
5+3*2%10-8*6
Correct Answer
A. -37
Explanation
The given arithmetic expression follows the order of operations, which is parentheses, multiplication and division (from left to right), and addition and subtraction (from left to right). Firstly, the expression 3*2 is evaluated, resulting in 6. Then, the expression 6%10 is evaluated, resulting in 6. Next, the expression 5+6-8*6 is evaluated. Multiplication is performed first, resulting in 48. Then, addition and subtraction are performed from left to right, resulting in -37. Therefore, the correct answer is -37.
3.
What will be the output of the following statement ?
printf( 3 + "goodbye");
Correct Answer
C. Dbye
Explanation
The statement `printf( 3 + "goodbye");` will output "dbye". This is because the number 3 is added to the address of the string "goodbye". Adding a number to a string pointer causes the pointer to move forward by that many characters. In this case, the pointer moves forward by 3 characters, skipping the first three characters of the string "goodbye" and starting the output from the fourth character, which is "d".
4.
Void main()
{
int a=10,b=20;
char x=1,y=0;
if(a,b,x,y)
{
printf("EXAM");
}
}
What is the output?
Correct Answer
D. Nothing is printed
Explanation
The if statement in the code is using the comma operator, which evaluates all the expressions separated by commas and returns the value of the last expression. In this case, the expressions are a, b, x, and y. Since all of these variables have non-zero values, the result of the comma operator is the value of y, which is 0. Since the condition in the if statement evaluates to false, the code inside the if block is not executed, and nothing is printed.
5.
What will be the output of the following statement ?
printf("%X%x%ci%x",11,10,'s',12);
Correct Answer
B. Basc
Explanation
The given statement is using the printf function to print a formatted string. The format string contains multiple format specifiers, such as %X, %x, %c, and %i. The values provided as arguments to the printf function are 11, 10, 's', and 12.
The %X specifier is used to print the value 11 in hexadecimal uppercase format, which is B.
The %x specifier is used to print the value 10 in hexadecimal lowercase format, which is a.
The %c specifier is used to print the character 's'.
The %i specifier is used to print the value 12 in decimal format, which is 12.
Therefore, the output of the statement will be "Basc".
6.
What will be the value of `a` after the following code is executed
#define square(x) x*x
a = square(2+3)
Correct Answer
C. 11
Explanation
The code defines a macro called `square` which takes an argument `x` and returns the square of `x`. In this case, the argument passed to `square` is `2+3`. According to the order of operations, the addition is performed first, resulting in `5`. Then, the macro is expanded as `5*5`, which evaluates to `25`. Therefore, the value of `a` after the code is executed should be `25`.
7.
What would be the output of the following program?
#include
main()
{
char str[]="S\065AB";
printf("\n%d", sizeof(str));
}
Correct Answer
B. 6
Explanation
The program declares a character array named "str" and initializes it with the string "S\065AB". The escape sequence "\065" represents the octal value for the character 'A'. The sizeof() function is then used to determine the size of the array, which is 6 bytes. The printf() function is used to print the size of the array on a new line. Therefore, the output of the program would be 6.
8.
What will be the output of the following statements ?
int i = 3;
printf("%d%d",i,i++);
Correct Answer
B. 43
Explanation
The output of the given statements will be "43". The printf statement first evaluates the format string, which is "%d%d". Then it evaluates the arguments, which are "i" and "i++". The value of "i" is 3 initially, so the first "%d" in the format string is replaced with 3. However, the second "%d" is also replaced with 3 because the post-increment operator (i++) increments the value of "i" after it is used in the expression. Therefore, the final output is "43".
9.
What will be output if you will compile and execute the following c code?
#include
int main(){
float f;
f=3/2;
printf("%f",f);
return 0;
}
Correct Answer
C. 1.000000
Explanation
The code snippet is dividing an integer value 3 by an integer value 2, which results in an integer division. Since both 3 and 2 are integers, the result of the division will be an integer as well. The integer division of 3 by 2 is 1. The result is then assigned to the variable f, which is a float. However, since the value is assigned to a float variable after the division has already been performed as an integer division, the decimal part is truncated. Therefore, the output will be 1.000000.
10.
What will be output if you will compile and execute the following c code?
#include
int main(){
int a=15,b=10,c=5;
if(a>b>c )
printf("Trre");
else
printf("False");
return 0;
}
Correct Answer
B. False
Explanation
The code compares the values of a, b, and c using the nested if statement. However, the condition a>b>c is not valid in C programming. Therefore, the code will execute the else block and print "False" as the output.