Professional Documents
Culture Documents
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.
#include<stdio.h>
void main(void){
int x=11,i;
for(i=0;i<x;i+=3){
printf("Start: i is [%d]\n",i);
continue;
printf("End: i is [%d]\n",i);
}
}
2 What is the outcome/output of the following C Function goes right to left, int is already
program, if any? doesn’t print 1 for some reason, equals one
so it moves to next interger to the right, it
#include<stdio.h> equals -1 so it prints
void main(void){
int i=1;
for(i=0;i=-1;i=1) {
printf("%d ",i);
if(i!=1) break;
}
}
3 What is the outcome/output of the following C Counts from 5 to 0
program, if any? Each loop subtracts one then as it gets to 0 !
becomes true and exits loop to break
#include<stdio.h>
void main(void){
int a=5;
for(;;) {
printf("%d ",a);
if(!a--)
break;
}
}
4 What is the outcome/output of the following C Just prints a 0
program, if any?
/* Note the ; at the end of for statement */
#include<stdio.h>
void main(void){
int i;
for(i=0;i>=5;i++);
printf("%d",i);
}
5 What is the outcome/output of the following C Blank without that ;
program, if any?
#include<stdio.h>
void main(void){
int i;
for(i=0;i>=5;i++)
printf("%d",i);
}
6 What is the outcome/output of the following C Prints 10 11 12 13 14 15 stops at 15
program, if any?
#include<stdio.h>
void main(void){
int i;
for(i=10;i<=15;i++){
while(i){
do{
printf("%d\n",i);
if( i >1)
continue;
}while(0);
break;
}
}
}
7 What is the outcome/output of the following C C++0 1 2 3
program, if any?
#include<stdio.h>
void main(void){
int x=123;
int i= printf("c" "++");
for(x=0;x<=i;x++){
printf("%x ",x);
}
}
8 What is the outcome/output of the following C Swap the break and print f and it will print f
program, if any? when it counts up to 5
#include<stdio.h>
void main(void)
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("Orlando");
}
}
9 What is the outcome/output of the following C
program, if any?
#include<stdio.h>
void main(void) 6
{
int i=0; If you remove the ; after for it will count to
for(; i<=5; i++); 5 and then exit
printf("%d", i);
}
10 What is the outcome/output of the following C
program, if any?
#include<stdio.h>
void main(void)
{
int i=0;
for(; i<=5; i++){
printf("%d", i);
++i;
}
}
11 Point out the error, if any in the for loop.
#include<stdio.h>
void main(void)
{
int i=1;
for(;;)
{
printf("%d\n", i++);
if(i>10)
break;
}
}
12 Identify logical or syntax error in the for loop, if
any.
#include<stdio.h>
int main(void)
{
int x=5;
for(;;x++)
{
printf("%d\n", x);
if(x>10)
break;
x++;
}
return 0;
}
A.for loop requires three components
B.variable x is incremented twice
C.it's an infinite loop.
D. All the above
E. No error
#include<stdio.h>
void main(void){
switch(0X0){
case '\0':printf("\0");
break;
case 0: printf("0");
break;
default: printf("default");
}
}
21 What is the outcome/output of the following C
program, if any?
#include<stdio.h>
void main(void){
switch(0X0){
case '0':printf("0");
break;
case 0: printf("0");
break;
default: printf("default");
}
}
22 What is the outcome/output of the following C
program, if any?
#include<stdio.h>
void main(void){
switch(5/2*6+3.0){
case 3:printf("Beckham\n");
break;
case 15:printf("Ronaldo\n ");
break;
case 0:printf("Messi\n");
break;
default:printf(“Pele\n");
}
}
23 What is the outcome/output of the following C
program, if any?
#include<stdio.h>
void main(void){
unsigned char c=280;
switch(c){
printf("Start\t");
case 280:printf("Beckham\t");
case 24: printf("Messi\t");
default: printf("Ronaldo\t");
printf("End");
}
}
24 Which of the following cannot be checked in a
switch-case statement?
A. Character
B. Integer
C. Float
D. enum
25 Which of the following errors would be reported
by the compiler on compiling the program given
below?
#include<stdio.h>
void main(void)
{
int a = 5;
switch(a)
{
case 1:
printf("First\n");
case 2:
printf("Second\n");
case 3 + 2:
printf("Third\n");
case 5:
printf("Final\n");
break;
}
}
A. There is no break statement in each case.
B. Expression as in case 3 + 2 is not allowed.
C. Duplicate case ‘case 5’:
D. No error will be reported.
26 Point out the error, if any in the program.
#include<stdio.h>
void main(void)
{
int P = 10;
switch(P)
{
case 10:
printf("Case 1\n");
case 20:
printf("Case 2\n");
break;
case P:
printf("Case 2\n");
break;
}
}
A. Error: No default value is specified
B. Error: Constant expression required at line
case P:
C. Error: There is no break statement in each
case.
D. No error will be reported.
27 Point out the error, if any in the program.
#include<stdio.h>
void main(void)
{
int i = 1;
switch(i)
{
case 1:
printf("Case1\n");
break;
case 1*2+4:
printf("Case2\n");
break;
}
}
A. Error: in case 1*2+4 statement
B. Error: No default specified
C. Error: in switch statement
D. No Error
28 Which of the following sentences are correct
about a switch loop in a C program?
1: switch is useful when we wish to check
the value of variable against a particular set of
values.
2: switch is useful when we wish to check
whether a value falls in different ranges.
3: Compiler implements a jump table for
cases used in switch.
4: It is not necessary to use a break in every
switch statement.
A. 1,2
B. 1,3,4
C. 2,4
D. 2
29 Break is used to take control out of switch and
continue to take control of the beginning of the
switch.
A. Yes
B. No
30 Can we use a switch statement to switch on
strings?
A. Yes
B. No
31 We want to test whether a value lies in the range
2 to 4 or 5 to 7. Can we do this using a switch?
A. Yes
B. No
32 What is the outcome/output of the following C Just says hi
program, if any?
#include<stdio.h>
void main(void)
{
int i = 1;
switch(i)
{
printf("Hello\n");
case 1:
printf("Hi\n");
break;
case 2:
printf("\nBye\n");
break;
}
}
33 Do logical operators in C language use short yes
circuit?
A. Yes
B. No
C. N/A. Circuit operation applicable only for
hardware.
34 What is the outcome/output of the following C Prints 10????? Just adds two to all varaibles
program, if any?
#include<stdio.h>
void main(void){
int x=8;
do{
do{
printf("%o",x);
}
while(!-2);
}
while(0);
}