Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
http://www.cquestions.com/2012/02/data-type-questions-in-c.html
http://www.indiabix.com/c-programming/pointers/
For every question you work on, observe and understand why certain outcome is unexpectedly different than what should have been a
straight forward outcome. The objective of the questions is to get you familiar with the different ways C operates.
If the code generates a compilation error, then identify the reason for the error and fix it.
111
2 What is the outcome/output of the following C Prints all on same line, no indent
program, if any?
#include<stdio.h>
void main(void){
int a=100;
if(a>30)
printf(" Greater than 30 ");
if(a>20)
printf("Greater than 20 ");
if(a>10)
printf("Greater than 10 ");
}
3 What is the outcome/output of the following C Just prints 30 because initial condition was satisfied
program, if any?
#include<stdio.h>
void main(void){
int a=100;
if(a>30)
printf(" Greater than 30 ");
else if(a>20)
printf("Greater than 20 ");
else if(a>10)
printf("Greater than 10 ");
}
4 What is the outcome/output of the following C Greater than 30 not less than 20 greater than 10
program, if any?
#include<stdio.h>
void main(void){
int a=100;
if(a>30)
printf(" Greater than 30 ");
if(a<20)
printf("Less than 20 ");
else
printf("Not less than 20 ");
if(a>10)
printf("Greater than 10 ");
}
5 What is the outcome/output of the following C Greater than 30 n0t less than 20
program, if any?
#include<stdio.h>
void main(void){ Greater than 30 not less than 20
int a=100;
if(a>30)
{
printf(" Greater than 30 ");
if(a<20)
printf("Less than 20 ");
else
printf("Not less than 20 ");
}
else if(a>10)
printf("Greater than 10 ");
}
6 What is the outcome/output of the following C Just greater than 10, initial condition statement not met,
program, if any? moves to else if
#include<stdio.h>
void main(void){
int a=100;
if(a < 30)
{
printf(" Less than 30 ");
if(a > 20)
printf("Greater than 20 ");
else
printf("Not greater than 20 ");
}
else if(a>10)
printf("Greater than 10 ");
}
7 What is the outcome/output of the following C Shows not equal even though values are equal??
program, if any?
#include<stdio.h>
void main(void){
int x=-1,y=-1;
if(++x = ++y)
printf(" Equal ");
else
printf("Not equal %d %d, x, y");
}
#include<stdio.h>
void main(void){
int x=1;
if(--x)
printf("The Godfather");
--x;
else
printf("%d",x);
}
13 Which of the following statements are correct about the
below program?
#include<stdio.h>
void main(void)
{
int i =5, j = 20;
if(i = 5) && if(j = 20)
printf("Have a nice day");
}
if(10==b)
printf(" b is 10 ");
else
printf("b is not 10");
if(a=0)
printf(" a is 0");
else
printf("a is not 0");
if(7=a)
printf(" a is 7");
else
printf("a is not 7");
}
15 What is the outcome/output of the following C Not equal, I is postincrement adding 1 so &&
program, if any?
void main(void)
{
int i = 1;
if (i++ && (i == 1))
printf("Equal n");
else
printf("Not equal\n");
}
16 What is the outcome/output of the following C
program, if any?
int main(void)
{
int a = 10, b = 10;
if (a = 5)
b--;
printf("a=%d, b=%d\n", a, b--);
}
A. a = 10, b = 9
B. a = 10, b = 8
C. a = 5, b = 9
D. a = 5, b = 8
17 What is the outcome/output of the following C
program, if any?
void main(void)
{
int i = 0,y;
int x = ++i,
y = i++;
printf("%d % d %d \n", x, y,i);
}
void main(void){
int x=4;
while(3){
do{
printf("%d",x);
} while(0);
};
}
21 What is the outcome/output of the following C ** might have to wait until we cover break and continue
program, if any?
#include<stdio.h>
void main(void)
{
int i=1;
while()
{
printf("%d\n", i++);
if(i>10)
break;
}
}
A. There should be a condition in the while loop
B. There should be at least a semicolon in the while
C. The while loop should be replaced with for loop.
D. All the above
E. No error
#include <stdio.h>
int main(void)
{
int x = 2, y = 2;
x /= x / y;
printf("%d\n", x);
return 0;
}
23 What is the outcome/output of the following C Try this on any online compiler and compare output
program, if any?