Hardest Trivia Quiz On Output Of C Programs! Test

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Himasri
H
Himasri
Community Contributor
Quizzes Created: 5 | Total Attempts: 2,522
Questions: 10 | Attempts: 431

SettingsSettingsSettings
Hardest Trivia Quiz On Output Of C Programs! Test - Quiz

.


Questions and Answers
  • 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; }

    • A.

      2

    • B.

      3

    • C.

      5

    • D.

      Garbage Value

    • E.

      None of the above

    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.

    Rate this question:

  • 2. 

    What will be the output of the following arithmetic expression ? 5+3*2%10-8*6

    • A.

      -37

    • B.

      -42

    • C.

      -32

    • D.

      -28

    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.

    Rate this question:

  • 3. 

    What will be the output of the following statement ? printf( 3 + "goodbye");

    • A.

      Goodbye

    • B.

      Odbye

    • C.

      Dbye

    • D.

      Bye

    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".

    Rate this question:

  • 4. 

    Void main() { int a=10,b=20; char x=1,y=0; if(a,b,x,y) { printf("EXAM"); } } What is the output?

    • A.

      XAM is printed

    • B.

      Exam is printed

    • C.

      Compiler Error

    • D.

      Nothing is printed

    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.

    Rate this question:

  • 5. 

    What will be the output of the following statement ? printf("%X%x%ci%x",11,10,'s',12);

    • A.

      Error

    • B.

      Basc

    • C.

      Bas94c

    • D.

      None of these

    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".

    Rate this question:

  • 6. 

     What will be the value of `a` after the following code is executed #define square(x) x*x a = square(2+3)

    • A.

      25

    • B.

      13

    • C.

      11

    • D.

      10

    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`.

    Rate this question:

  • 7. 

    What would be the output of the following program? #include main() { char str[]="S\065AB"; printf("\n%d", sizeof(str)); }

    • A.

      7

    • B.

      6

    • C.

      5

    • D.

      Error

    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.

    Rate this question:

  • 8. 

    What will be the output of the following statements ? int i = 3; printf("%d%d",i,i++);

    • A.

      34

    • B.

      43

    • C.

      44

    • D.

      33

    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".

    Rate this question:

  • 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; }

    • A.

      1.5

    • B.

      1.500000

    • C.

      1.000000

    • D.

      Compiler error

    • E.

      None of above

    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.

    Rate this question:

  • 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; }

    • A.

      True

    • B.

      False

    • C.

      Run time error

    • D.

      Compiler error

    • E.

      None of above

    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.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Mar 20, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 06, 2012
    Quiz Created by
    Himasri
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.