C questions


C multiple choice questions and answers


1.

The array a[j][k] is equivalent to

(A) ((base type*)a+(j*row length)+k)
(B)
*((base type*)a+(j*row length)+k)
(C) *((base type)a+(j*row length)+k)
(D) *((base type)a+(j*row length)) 
(E) None of these 


Explanation:
**

2.

What will be output of the following c program?

#include<stdio.h>
int main(){
int a[]={6,7,8,9},i;
    compute(a);
    for(i=3;i>=0;i--)
         printf(“%d”,a[i]);

return 0;
}

compute(int *p){
int i;
    for(i=0;i<4;i++){
       *p=*p-1;
        p++;
    }
}

(A) 5 6 7 8
(B) 6 7 8 9
(C) 8 7 6 5
(D) None of these 
(E) Compilation error


Explanation:
**

3.

What will be output of the following c program?

#include<stdio.h>
int main(){
    int a[]={4,5,6,7,8},i,*p;
    for(p=a+4,i=2;i<=4;i++)
       printf(“%d”,p[-i]);
return 0;

}

(A) 6  
(B) 6 5 4    
(C) 8 7 6 5 4  
(D) 6 7 8  
(E) Compilation error

Explanation:
**

4.

What will be output of the following c program?

#include<stdio.h>
int main(){
    int a[2][2][3]={{1,2,3,6,7,8},
                    {5,7,9,3,4,1}
  };
    printf(“%d”,*(*(*(a+1)+1)+1));
return 0;

(A)
(B) 3
(C) 4
(D) 6
(E) Compilation error


Explanation:
**

5.

What will be output of the following c program?

#include<stdio.h>
int main(){
    char str[]="HELLO";
    char *p= "HAI";
    str="INDIA";
    printf("%s",str);
    return 0;

(A) HELLO
(B) HAI
(C) INDIA
(D) Compilation error
(E) None of these  


Explanation:
**

6.

What will be output of the following c program?

#include<stdio.h>
int main(){
char * emp name= "raja";
printf("%s",emp name);
return 0;
}

(A) raja
(B) ra
(C) r
(D) Compilation error
(E) None of these


Explanation:

Invalid variable name. Except underscore there should not be any special character in name of variable even blank space.

7.

What will be output of the following c program?

#include<stdio.h>
int main(){
long int new=5l;
printf("%ld",new);
return 0;
}
(A) 5
(B) 51
(C) 0
(D) Compilation error
(E) None of these


Explanation:
We can use c++ keyword in variable name in c programming. (But should not use , why ?)

8.

What will be output of the following c program?

#include<stdio.h>
int main(){
long int _=5l;
printf("%ld",_);
return 0;
}

(A) 5
(B) 51
(C) 0
(D) Compilation error
(E) None of these


Explanation:

Underscore is valid identifier in c.

9.

What will be output of the following c program?

#include<stdio.h>
int  main(){
char * __WORLD__="world";
printf("%s ",__WORLD__);
return 0;
}

(A) world
(B) null
(C) __WORLD__
(D) Compilation error
(E)
None of these


Explanation:

__WORLD__ is valid identifier in c programming language. But we should not write variable name in the forma like __xyx__, __TIME__. Why ? 

10.

What will be output of the following c program?

#include<stdio.h>
int main(){
char * __TIME__="world";
printf("%s ",__TIME__);
return 0;
}
(A) world
(B) null
(C) w
(D) Compilation error
(E) None of these


Explanation:


__TIME__ is valid identifier in c programming language but it is predefine global identifier. So a variable not should not be global identifier like__TIME__, __DATE___, __FILE__ etc.



11.

What will be output of the following c program?

#include<stdio.h>
int main(){
long int a;
(float)a=6.5;
printf("%f",a);
return 0;
}
(A) 6.5
(B) 6.500000
(C) 7.000000
(D) Compilation error
(E) None of these


Explanation:

After applying any operator in variable name it always give a value.
(type): urinary type casting operator is not exception for this.
It is similar to write
3456=5
It is invalid c statement. Because left side of assignment operator must be a variable not any constant.

12.

What will be output of the following c program?

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

(A) 10
(B) 0
(C) 11
(D) Compilation error
(E) None of these


Explanation:

After applying any operator in variable name it always give a value.
(type): urinary type casting operator is not exception for this.
It is similar to write
3456=5
It is invalid c statement. Because left side of assignment operator must be a variable not any constant.

13.

What will be output of the following c program?

#include<stdio.h>
int main(){
long int a,b=5;;
~a=++b + ++b + ++b;
printf("%d  %d",++a,++b);
return 0;
}


(A) 5
(B) 6
(C) 7
(D) Compilation error
(E) None of these


Explanation:

After applying any operator in variable name it always give a value.
(type): urinary type casting operator is not exception for this.
It is similar to write
3456=5
It is invalid c statement. Because left side of assignment operator must be a variable not any constant.

14.

What will be output of the following c program?

#include<stdio.h>
int main(){
int x;
int y;
x+y=10;
x=3;
printf("%d",y);
return 0;
}

(A) 10
(B) 7
(C) Garbage value
(D) Compilation error
(E) None of these


Explanation:

After applying any operator in variable name it always give a value.
(type): urinary type casting operator is not exception for this.
It is similar to write
3456=5
It is invalid c statement. Because left side of assignment operator must be a variable not any constant.

15.

What will be output of the following c program?

#include<stdio.h>
int main(){
int x=5;
int y=10;
&x=y;
printf("%d %d",x,y);
return 0;
}
(A) 5 10
(B) 10 5
(C) 10 10
(D) Compilation error
(E) None of these


Explanation:

After applying any operator in variable name it always give a value.
(type): urinary type casting operator is not exception for this.
It is similar to write
3456=5
It is invalid c statement. Because left side of assignment operator must be a variable not any constant.

16.

What will be output of the following c program?

#include<stdio.h>
int main(){
const a=10;
a=~a;
printf("%d",a);
return 0;
}
(A) 10
(B) -11
(C) 12
(D) Compilation error
(E) None of these


Explanation:

We cannot modify a const object.

17.

What will be output of the following c program?

#include<stdio.h>
int main(){
const _=10;
int *p=&_;
printf("%d",*p);
}

(A) 10
(B) 11  
(C) Any address
(D) Compilation error
(E) None of these


Explanation:

We can assign address of const object to its pointer. Underscore is valid variable name.

18.

What will be output of the following c program?

#include<stdio.h>
int main(){
const int *a=12;
a++;
printf("%d",a);
return 0;
}
(A) 12
(B) 13
(C) 14
(D) Compilation error
(E) None of these


Explanation:

Here address of variable a is constant not variable a. So we can modify variable a. Initial value of auto type data is garbage.

19.

What will be output of the following c program?

#include<stdio.h>
int main(){
const int *a=(const int * )12;
*a=(const int *)25;
printf("%d",a);
return 0;
}

(A)
12
(B) 25
(C) Any address
(D) Compilation error
(E) None of these


Explanation:

We cannot modify a const object. Here address of variable a is constant not variable a.

20.

What will be output of the following c program?

#include<stdio.h>
int main(){
int * const a=(int * const)12;
a=25;
printf("%d",a);
return 0;
}

(A) 12
(B) 25
(C) Any address
(D) Compilation error
(E) None of these


Explanation:

We cannot modify a const object. Here address of variable a is not constant but variable a is constant. So we cannot modify variable a.


Post a Comment