0% found this document useful (0 votes)
84 views6 pages

Output Based Que (2) 2

The document contains 18 code snippets with questions about their output. The summaries are: The code snippets cover a range of C programming concepts like loops, operators, precedence, break/continue statements, and data types. Most snippets output simple values or strings based on the logic in the code. A few result in compilation errors due to syntax issues or invalid operations like dividing by zero.

Uploaded by

Simple Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views6 pages

Output Based Que (2) 2

The document contains 18 code snippets with questions about their output. The summaries are: The code snippets cover a range of C programming concepts like loops, operators, precedence, break/continue statements, and data types. Most snippets output simple values or strings based on the logic in the code. A few result in compilation errors due to syntax issues or invalid operations like dividing by zero.

Uploaded by

Simple Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Q1. What will be output of following c code?

#include<stdio.h>
int main(){
int x=011,i;
for(i=0;i<x;i+=3){
printf("Start ");
continue;
printf("End");
}
return 0;
}
Output: Start Start Start

Q2. What is the output of this C code?


#include <stdio.h>
void main()
{
int k = 0;
for (k)
printf("Hello");
}
Output: Error

Q3. What will be output of following c code?

#include<stdio.h>
int main(){
int i,j;
i=j=2,3;
while(--i&&j++)
printf("%d %d",i,j);
return 0;
}

Output: 13
Q4. What will be output of following c code?
#include<stdio.h>
int main(){
static int i;
for(++i;++i;++i) {
printf("%d ",i);
if(i==4) break;
}
return 0;
}
Output: 24
Q5. What will be output of following c code?

#include<stdio.h>
int main(){
int i;
for(i=0;i<=5;i++);
printf("%d",i)
return 0;
}
Output: 6
Q6. What will be output of following c code?

#include<stdio.h>
int i=40;
extern int i;
int main(){
do{
printf("%d",i++);
}
while(5,4,3,2,1,0);
return 0;
}
Output: 40
Explanation:
Initial value of variable i is 40
First iteration:
printf function will print i++ i.e. 40
do - while condition is : (5,4,3,2,1,0)
Here comma is behaving as operator and it will return 0. So while condition
is false hence program control will come out of the loop.
Q7. What will be output of following c code?
#include<stdio.h>
int main(){
int i;
for(i=10;i<=15;i++){
while(i){
do{
printf("%d ",1);
if(i>>1)
continue;
}while(0);
break;
}
}
return 0;
}

Output: 1 1 1 1 1 1
For loop will execute six times.
Note: continue keyword in do-while loop bring the program its while
condition (while(0)) which is always false.
Q8. What will be the output of the following program?
#include<stdio.h>

int main()
{
int i=2,j=2;
while(i+1?--i:j++)
printf("i=%d j=%d",i,j);
return 0;
}

Output: 1 2

Q9. What will be the output of the following 2 programs?

#include<stdio.h>
void main()
{
int i;
for(i=1,printf("Intialization");printf("\nCondition"),i++
<= 5;printf("%d",i))
printf("\nInside the loop\n");
}
Program 2:
#include<stdio.h>
void main()
{
int i;
for(i=1,printf("Initialization");i++ <=
5,printf("\nCondition");printf("%d",i))
printf("\nInside the loop :");
}
Output:
Program 1:
Initialization
Condition
Inside the loop:2
Condition
Inside the loop:3
Condition
Inside the loop:4
Condition
Inside the loop:5
Condition
Inside the loop:6
Program 2:
Infinite Loop
Q10. What will be the output of the following program?

main ()
{
int i;
for (i=2;i<=10;i++)
{
switch (i)
{
case 2:
printf ("H");
continue;
case 3:
break;
case 4:
case 5:
printf ("m");
break;
default:
printf (!);
}
}
}
Output:
Hmm!!!!!

Q11. What will be the output of the following program?


#include<stdio.h>
void main()
{
int i=0;
while(i <10); // line 5
{
printf("%d ",i); // line 7
i++; // line 8
}
}

Output: Infinite Loop

Q12. What will be the output of the following program?

main()
{
int x = 10, y, z;
z=y=x;
y-= x--;
z -= --x;
x -= --x - x--;
printf ("y = %d z = %d x = %d", y, z, x);
}

Output : y=0z = 2x = 6
Q13. What will be the output of the following program?
main()
{
inta = 10, b = 10;
printf ("ans = %d", a>b?a*a:b/b);
}

Output ans = 1
Q14. What will be output when you will execute following c
code?

#include<stdio.h>
void main(){
int a=5,b=10,c=1;
if(a&&b>c){
printf("cquestionbank");
}
else{
break;
}
}
Output :Compilation error

Q15. What will be output when you will execute following c


code?

#define True 5==5


#include<stdio.h>
void main(){
if(.001-0.1f)
printf("David Beckham");
else if(True)
printf("Ronaldinho");
else
printf("Cristiano Ronaldo");
}

Q16. What is the output of this C code?

#include <stdio.h>
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
printf("%d %d\n", l, k);
return 0;
}

Output: -1 1
Q17. What is the output of this C code?

#include <stdio.h>
void main()
{
int x = 5.3 % 2;
printf("Value of x is %d", x);
}
Output: Compile time error

Q18. What is the output of this C code?

#include <stdio.h>
int main()
{
int a = 1, b = 1, d = 1;
printf("%d, %d, %d", ++a + ++a+a++, a++ + ++b, ++d +
d++ + a++);
}

Output: 14, 4, 5

Q12. Convert the following number:

(i) (34)6 = ()9 =(34)3


(ii) (A4)16 = ()8 =(34)5
(iii) (256.15)6 = ()16 =()10

You might also like