100% found this document useful (1 vote)
308 views

Questions

This document contains questions about C programming concepts like variables, operators, functions, arrays, pointers, structures and more. It tests understanding of: - Printf format specifiers and order of evaluation - Binary representations and bitwise operators - Pointer arithmetic and dereferencing - Array indexing and passing arrays to functions - Structure definitions and accessing members - String handling functions like strlen()

Uploaded by

harshitha7
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
308 views

Questions

This document contains questions about C programming concepts like variables, operators, functions, arrays, pointers, structures and more. It tests understanding of: - Printf format specifiers and order of evaluation - Binary representations and bitwise operators - Pointer arithmetic and dereferencing - Array indexing and passing arrays to functions - Structure definitions and accessing members - String handling functions like strlen()

Uploaded by

harshitha7
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

C language

1.Whether they are legal

Variables 2. Output?
Percent main()
y2x5__fg7h {
annual profit char a[4]="HELL";
_1990_tax printf("%s",a);
savings#account }
Double
9winter 3. The statement- printf("%d",printf("nal")); prints
1) 3 2) nal 3) nal3 4) 3nal

4. The program fragment -for(count=1;count<5;++count) if(count==3) continue; else


printf("%d",count);
1) prints 1245 2) prints 124 3) prints 1234 4)none of the above

5. The statement printf("%d",++5); will print


1) 6 2) 5 3) garbage 4) It will give an error message

6. The statement -printf("%d",10?0?5:11:12); will print


1) 0 2) 10 3) 11 4) 12

7. What does the value of count signify in the following pogram fragment ? int x=45;int
count=1; while(x=x&(x-1)) count++;
1) number of 0 in binary equivalent of x 2) No of 1 in binary equivalent of x
3) 1's complement of x 4) summation of 0s and 1s in the binary equivalent of x

8. The program fragment- for(count=3;count<15;count+=3);printf("%d",count); prints


1) 15 2) 36912 3) 12 4) none of the above

9. The following program fragment prints which of the following : int x=109 , y=5 ;
printf((y>7)? "%d": "%c",x);
1) It will cause an execution error 2) It will produce syntax error
3) It will print m 4) none of the above

10. What does following code segment print : int a=500,b=100,c=30,d=40,e=19;


a+=b-=c*=d/=e%=5;printf("%d %d %d %d %d",a,b,c,d,e);
1) 300 -200 300 10 4 2) 500 -200 300 10 4
3 garbage values not of our interests 4) 300 -200 300 40 4

11. Following program fragment - int i;i = 2; i = i ^ 2; printf("i = %d\n", i); i = i ^ 1;


printf("i = %d\n", i);
1) prints i=2 i=4 2) prints i=1 i=1 3) prints i=0 i=1 4)none of the above
12. #include<stdio.h> return 0;
int main() }
{ The output of the above code is
char *p = "MISTRAL"; 1)5 2)10 3) error 4)garbage
printf ("%c\t", *(++p));
p -=1; 16. Ascii values of 'a','b','c','\n',and '\0'
printf ("%c\t", *(p++)); are 97,98,99,10,and 0 respectively.
return 0; Then What will be the output of
} following program
The output of the above program will be
1)I M 2) M I 3) M M 4) T S #include<stdio.h>
int main()
13. #include<stdio.h> {
int main() char s[]={'a','b','c','\n','c','\0'};
{ char *p,*str,*str1;
int a[]={5,4,3,2,1}; p=&s[3];
int x,y; str=p;
int *p=&a[2]; str1=s;
*p++; printf("%d",++*p + ++*str1-32);
x=++*p; return 0;
y=*(p++); }
printf("%d %d",x,y);
return 0; 17. int main ( )
} {
Output of the above code segment is static char *s[ ] = {"black", "white",
1)3 3 2)3 4 3) 4 3 4)2 3 "yellow", "violet"};
char **ptr[ ] = {s+3, s+2, s+1, s}, ***p;
14. int main() p = ptr;
{ **++p;
int a[]={9,4,1,7,5}; printf("%s",*--*++p + 3);
int *p; return 0;
p=&a[3]; }
printf("%d",p[-1]); Output of the above program is
return 0; 1) ck 2) error 3) te 4) et
}
18. int main()
output of the above code is {
1)6 2)1 3)7 4)error message char *s[]={ "Artcent","Flexthonity"};
char **p;
15. int main() p=s;
{ printf("%s ",++*p);
const int x=5; printf("%s ",*p++);
int *ptrx; printf("%s ",++*p);
ptrx=&x; return 0;
*ptrx=10; }
printf("%d",x); The above program will print
19. A function 'q' that accepts a pointer 25. main()
to a character as argument and returns a {struct date;
pointer to an array of integer can be struct student
declared as: { char name[30];
1) int (*q(char*)) [] 2) int *q(char*) [] struct date dob;
3) int(*q)(char*) [] 4)none of the above }stud;
struct date
20. int main() {
{ static int a[]={7,8,9}; int day,month,year;
printf("%d",2[a]+a[2]); };
return 0; scanf("%s%d%d",
} stud.rollno,
The above program will give output as &student.dob.day,
&student.dob.year);
21. void main() }
{ void *v; 26. main()
int integer=2; {
int *i=&integer; int i=258;
v=i; char *ptr = &i;
printf("%d",(int*)*v); *++ptr=3;
}output???? printf("%d",i);
}
22. void main() outout???
{printf(“ %d \t“, sizeof( void *));
printf(“ %d \t”, sizeof(int *)); 27. main()
printf(“ %d \t”, sizeof(double *)); {
printf(“%d\t”,sizeof(struct unknown *)); int i = 258; int *iPtr = &i;
} printf("%d %d", *((char*)iPtr),
output???? *((char*)iPtr+1) );
}
23. Is the following code legal? 28. #define DIM( array, type)
typedef struct a aType; sizeof(array)/sizeof(type)
struct a main()
{int x; {
aType *b; int arr[10];
}; printf(“The dimension of
24. Is the following code legal? the array is %d”, DIM(arr, int));
void main() }
{ typedef struct a aType; output??
aType someVariable; 29. int DIM(int array[])
struct a { return sizeof(array)/sizeof(int );
{ int x; }
aType *b; main()
}; {int arr[10];
} printf(“The dimension of the
array is %d”, DIM(arr)); }
30. main() printf( “%d”+0,123);
{ char *p="GOOD"; } output??
char a[ ]="GOOD";
printf("\n sizeof(p) = %d, sizeof(*p) = 38. void main(){
%d, strlen(p) = %d", sizeof(p), printf(“%d”+1,123);
sizeof(*p), strlen(p)); } output??
printf("\n sizeof(a) = %d, strlen(a) =
%d", sizeof(a), strlen(a)); 39. void main(){
} printf(“ %d”,
output???? printf(“hi!”)+printf(“bye”));
31. main() }output????
{
static int a[3][3]={1, 2, 3, 40. void main(){
4, 5, 6, printf(“%d”, printf(“hi!”)*printf(“bye”));
7, 8, 9}; }output????
int i,j; static *p[]={a,a+1,a+2};
for(i=0;i<3;i++) 41. void main(){
{ for(j=0;j<3;j++) printf(“hi friends”+3);
printf("%d\t%d\t%d\t%d\n",*(*(p+i)+j), } output??
*(*(j+p)+i),*(*(i+p)+j),*(*(p+j)+i));
} 42. void main(){
} printf(“c for”) + printf(“swimmers”);
} output???
32. void main()
{ 43. void main(){
printf(); printf(“\/\*\-*\/”)
} output?? } output??

33. void main() 44. int main() { int main=7;


{ {
printf( NULL); printf(“ %d”, main);
} output??? return main
}printf(“bye”);
34. void main() } output???

{ printf( “% %”,7); 45. void main() {


} output??? main();
} output??
35. void main()
{ printf(“/ /”,5); 46.void main() {
} output?? printf(“hard “ “work “);
} output??
36.void main()
{ printf(“d%”,8); 47. void main() {
} output??? char str[]=”%d”;int val=25;
37. void main(){ printf(srt,val);
}output?? 56. main()
{
48. void main() int i=10,j=20;
{ int val=10; j = i, j?(i,j)?i:j:j;
printf( “%d”, val+1,”%d”,val--); printf("%d %d",i,j);
}output?? } outout???

49. void main() { 57. void main()


int val,num; {
printf(“%d”,scanf(“%d%d”,&num, while(1){
&val)); if(printf("%d",printf("%d")))
} output?? break;
else
50.void main(){ int val= 97; continue;
“printing….”+printf(“%d”,val); }
} output?? } output???

51. void main() 68.main()


{ char str[]=”test”; {
if((printf(“%s”,str))==4) int i;
printf(“success”); i = abc();
else printf("%d",i);
printf(“fail”); }
} output?? abc()
{
52. void main(){ _AX = 1000;
int val=5; } output???
printf(“%d5”,val);
} output??
59. main()
53. void main(){ {
int vla=5; int i=-1;
printf(“%d”5+val++); -i;
} output?? printf("i = %d, -i = %d \n",i,-i);
} output???
54. main()
{int i=4,j=7; 60. main()
j = j || i++ && printf("YOU CAN"); {
printf("%d %d", i, j); int i=5,j=6,z;
} output??? printf("%d",i+++j);
55. main() }
{
int i=5,j=10;
i=i&=j&&10;
printf("%d %d",i,j);
} output??

You might also like