Trivia: Test On Output Of C Programs! Quiz

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Himasri
H
Himasri
Community Contributor
Quizzes Created: 5 | Total Attempts: 2,605
| Attempts: 348 | Questions: 10
Please wait...
Question 1 / 10
0 %
0/100
Score 0/100
1. What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){   register int i,x;   scanf("%d",&i);   x=++i + ++i + ++i;   printf("%d",x);   return 0; }

Explanation

The code will result in a compiler error. The reason for this is the use of the "register" keyword before the variable declaration. In modern C programming, the "register" keyword is considered obsolete and is no longer necessary. Some compilers may still support it, but in this case, it causes a conflict with the use of the "++" operator multiple times on the same variable in the expression "++i + ++i + ++i". This results in undefined behavior and a compiler error.

Submit
Please wait...
About This Quiz
Trivia: Test On Output Of C Programs! Quiz - Quiz

Are you a computer programmer looking for a way to refresh what you know when it comes to the output of C programs? If you said yes, then... see moreyou are in luck as the quiz is prepared to help you do just that. Give it a try and see if beyond might need to spend more hours studying for your finals. see less

2. What is the final value of x when the code int x; for(x=0; x<10; x++) {} is run?

Explanation

This code uses a for loop to increment the value of x. Here's how it works:

Initialization: x = 0; The variable x is initialized to 0.

Condition: x < 10; The loop continues as long as x is less than 10.

Increment: x++ After each iteration of the loop, x is incremented by 1.

The loop runs 10 times, with x taking on the values 0, 1, 2, 3,...9. After the 10th iteration, x becomes 10, which fails the condition x < 10, causing the loop to terminate. Therefore, the final value of x is 10.

Submit
3. What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){   asm{     mov bx,8;     mov cx,10     add bx,cx;   }   printf("%d",_BX);   return 0; }

Explanation

The given C code uses inline assembly to perform addition of the values stored in the registers bx and cx. The result, 18, is then printed using the printf function. Therefore, the output of the code will be 18.

Submit
4. What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){   enum xxx{      a,b,c=32767,d,e   };   printf("%d",b);   return 0; }

Explanation

The code will not compile because the enum value "b" is not assigned a value.

Submit
5. What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){   enum color{     RED,GREEN=-20,BLUE,YELLOW   };   enum color x;   x=YELLOW;   printf("%d",x);   return 0; }

Explanation

The code defines an enumeration called "color" with four possible values: RED, GREEN, BLUE, and YELLOW. The values are assigned implicitly, with RED being 0, GREEN being -20, BLUE being -19, and YELLOW being -18. The variable "x" is declared as an enum color and is assigned the value YELLOW. The printf statement then prints the value of "x", which is -18.

Submit
6. What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){   goto abc;   printf("main");   return 0; } void dispaly(){   abc:     printf("display"); }

Explanation

The code will result in a compiler error because the label "abc" is defined within the function "dispaly()" but it is being used outside of that function in the "main()" function. Labels can only be used within the function they are defined in.

Submit
7. What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){   char *url="c:\tc\bin\rw.c";   printf("%s",url);   return 0; }

Explanation

The given code declares a character pointer variable named "url" and assigns it the value "c:\tc\bin\rw.c". The printf statement then prints the value of "url", which is "c:\tc\bin\rw.c". Therefore, the output of the code will be "c:\tc\bin\rw.c".

Submit
8. What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){   float f=3.4e39;   printf("%f",f);   return 0; }

Explanation

The code declares a variable 'f' of type float and assigns it the value 3.4e39, which is a very large number. The printf function is then used to print the value of 'f'. Since the value of 'f' exceeds the maximum representable value for a float, it will be represented as positive infinity (+INF) when printed.

Submit
9. What will be output if you will compile and execute the following c code? #include<stdio.h> int main(){   int a=5;   int b=10;   {     int a=2;     a++;     b++;   }   printf("%d %d",a,b);   return 0; }

Explanation

The code declares two variables, a and b, and initializes them with the values 5 and 10 respectively. Then, inside a block of code, a new variable a is declared and initialized with the value 2. The value of this inner a is then incremented by 1, but it does not affect the value of the outer a. Similarly, the value of b is incremented by 1. Finally, the values of the outer a and b are printed, which are 5 and 11 respectively.

Submit
10. What will be output if you will compile and execute the following c code? #include<stdio.h> void call(int,int,int); int main(){   int a=10;   call(a,a++,++a);   return 0; } void call(int x,int y,int z){   printf("%d %d %d",x,y,z); }  

Explanation

This code snippet demonstrates the behavior of post-increment (a++) and pre-increment (++a) operators in C, along with the order of evaluation of function arguments.

Pre-increment (++a): The value of a is incremented before it's used in the expression.

Post-increment (a++): The value of a is incremented after it's used in the expression.

Order of evaluation:

While the order of evaluation of function arguments in C is unspecified, in this particular case, it seems the compiler evaluates them from right to left. Here's the breakdown:

++a: a is incremented to 11, then to 12. This 12 is passed as the third argument (z).

a++: The current value of a (12) is passed as the second argument (y). Then, a is incremented to 13 (but this value is unused).

a: The current value of a (12) is passed as the first argument (x).

Therefore, the call function receives the values 12, 11, and 12 for x, y, and z respectively, resulting in the output "12 11 12".

Submit
View My Results

Quiz Review Timeline (Updated): Sep 30, 2024 +

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

  • Current Version
  • Sep 30, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 06, 2012
    Quiz Created by
    Himasri
Cancel
  • All
    All (10)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What will be output if you will compile and execute the following c...
What is the final value of x when the code int x; for(x=0; x<10;...
What will be output if you will compile and execute the following c...
What will be output if you will compile and execute the following c...
What will be output if you will compile and execute the following c...
What will be output if you will compile and execute the following c...
What will be output if you will compile and execute the following c...
What will be output if you will compile and execute the following c...
What will be output if you will compile and execute the following c...
What will be output if you will compile and execute the following c...
Alert!

Advertisement