Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 41

**********regarding the aditi questions **************** points regarding c: 1.

the value of any variable will change as it is executing ex: for(i=0,j=0;i<5,j<25;i++,j++) %% the value of i and j will be 25 25 when it is printed 2. the value of any variable(i) will depend on the any values given or specified Ex: main() { extern int a; printf(a); } int a=5; %% the value of a is 5 3. the value of any variable will not depend on the function i.e scope EX: main() { int a; pirntf(a); } scope() { int a=4; } %% the value of a is not 4 but a junk 4. when main is recursed the execution will continue untill the stack gets overflow. 5. size of char * is 2 ************************************************************************

#include<stdio.h> #include<conio.h> void main() { clrscr(); static int c=5; printf("%d",c--); if(c) main(); getch(); }

//op is 1 see here there is no reintialization

/* exploring c notes */ #include<stdio.h> #include<conio.h> /*void function(a,b) { printf("%d%d",a,b); } */ void main() { clrscr(); int a,b; //printf("%d%c\n"); //garbage values //printf("%d%f",4,4); //floating point not linked /* scanf(" %d ",&a); printf("%d",a); // it asks for two values //no need for declaration of a,b;

scanf("%dhai iam fine %d",&a,&a); //gets only one values

will print the following continously : printf(" hai iam syed \ iam testing for contigious \ printing using printf statement\ using the backslash operator");

int d=500,c; b=100; if(!d >=400) b=300; c=200; printf("%d\t%d",b,c);

int x=2,y=5; y *=x; printf("%d",y);

// *= should come togeather

int x=3,z; z=x++ +x++; printf("%d%d",x,z);

// op :5,6

int x=3,z; z=++x*++x*++x; printf("%d",z);

// op :216

return(10,20);

// will return the second value i.e is 20

function(4,5);

int z=3; printf("%d",printf("%d%d%d%d%d",z,z,z,z,z)); //will print no of %d in II printf statement

float z=4.999999; printf("%d",z);

// junk values

pointer operations: -------------------

int *p; char *p1;

int q=3; char r=4; p=&q; printf("%p\t%p\n",p,&q); p1=&r; printf("%p\t%p\n",p1,&r); printf("%d%d",*p1,*p); */ printf(5+"fascimile"); ans:mile

**************************************************************************** /**********************size of various datatypes************************/ #include<stdio.h> #include<conio.h> void main() { clrscr(); printf("size of int is : %d",sizeof(int)); printf("\nsize of char is : %d",sizeof(char)); printf("\nsize of float is : %d",sizeof(float)); printf("\nsize of double is : %d",sizeof(double)); printf("\nsize of long is : %d",sizeof(long)); printf("\nsize of unsigned int is : %d",sizeof(unsigned int)); printf("\nsize of signed int is : %d",sizeof(signed int)); printf("\nsize of short is : %d",sizeof(short)); printf("\nsize of int* is : %d",sizeof(int*)); printf("\nsize of char* is : %d",sizeof(char*));

printf("\nsize of float* is : %d",sizeof(float*)); printf("\nsize of double* is : %d",sizeof(double*)); getch(); } /* answer size of size of size of size of size of size of size of size of size of size of size of size of */ ********************************************************************* #include<stdio.h> #include<conio.h> enum number { a=-1, b=4, c,d,e,}; main() { clrscr(); number n; printf("%d",e); getch(); } int is : 2 char is : 1 float is : 4 double is : 8 long is : 4 unsigned int is : 2 signed int is : 2 short is : 2 int* is : 2 char* is : 2 float* is : 2 double* is : 2

//0p : 7

******************************************************************* #include<stdio.h> #include<conio.h> void change(int *b,int n) { int i; for(i=0;i<n;i++) *(b+i)=*(b+i)+5; }

main() { clrscr(); int a[]={2,4,6,8,10};

int i; change(a,5); for (i=0;i<=4;i++) printf("\n %d",a[i]); getch(); } ************************************************************************* /* G:\ash\Qpapers\papers\c questions\oracle */ #include<stdio.h> #include<conio.h> #include<string.h> //void main (){clrscr(); /* 24 int n, sum=5; n=2; switch(n) { case 2:sum=sum-2; case 3:sum*=5; break; default:sum=0; } printf("%d",sum);

//prints

15

25 while(0) { printf("it is not an infinite loop "); }

26 int i=0; for(i=0;i<20;i++) { switch(i){ case 0: i+=5; case 1: i+=2; case 5: i+=5; default:

// 16 21

i+=4; break; } printf("%d\t",i); }

27 func(int i) { if(i%2) return 0; else return 1; } main() { clrscr(); int i=3; i=func(i); i=func(i); printf("%d",i);

//answer : 1

28 char*g() { static char x[1024]; return x; } void main() { clrscr(); char * g1="First String"; strcpy(g(),g1); g1=g(); //printf(g1); strcpy(g1,"Second String"); printf("Answer is:%s", g());

29) int a[5]={1,3,6,7,0}; int *b; b=&a[2]; printf("%d",b[-1]); */ getch(); }

************************************************************************* /* size of structures */

#include<stdio.h> #include<conio.h> struct ash { int a:1; //both int values are 1 int b:2; char c; //char is 1 double d; //double is 8 totally =10 }ash1; void main() { clrscr(); printf("\n %d ",sizeof(ash1)); getch(); } /* note : size of struct is 2 becos int a:1 is bitfield allocation when higher allocation than int is given it counts but when u give char it wont count for its size

************************************************************************** #include<stdio.h> #include<conio.h> /* void main() { clrscr(); printf(" Hello \o is the world "); getch(); }

// ans:Hello o is the world

void main() { int i=2; clrscr(); printf("%old %old %old %old ",i, i++,i--,i++); getch(); // right to left evaluation

} */ void main(){ int n,temp,result; clrscr(); n=7623; { temp=n/10; result=temp*10+ result; n=n/10; }

getch(); } ************************************************************************

#include<stdio.h> #include<conio.h> /**************** G:\ash\Qpapers\papers\c questions\ADITI ******************

1 #include<stdio.h> #include<conio.h> main() { clrscr(); extern int a; clrscr(); printf("%d",a);; } int a=20; answer :20 2 int a[5]={2,3}; printf("\n %d %d %d",a[2],a[3],a[4]); ans: 0 0 0 3 int i=-3,j=2,k=0,m; m=++i&&++j||++k; printf("\n %d %d %d %d",i,j,k,m);

ans : -2 3 0 1 4 int sumdig(int); int a,b; a=sumdig(123); b=sumdig(123); printf("%d %d",a, b); getch(); } sumdig(int n) { static int s=0; int d; if(n!=0) { d=n%10; n=(n-d)/10; s=s+d; sumdig(n); } else return(s); } answer :6 12 another: int a=1,b,d=1; b=a%10; d=(d-b)%10; printf("%d %d" ,b,d);

5 #define CUBE(x) (x*x*x) main() { int a,b=3; a=CUBE(b++); printf("\n %d %d",a,b); getch(); }

// 27 6

main() { clrscr(); char str[5]="fast"; static char *ptr_to_array = str; printf("%s",ptr_to_array); ANSWER :FAST

int num,*p; num=5; p=&num; printf("%d",*p); ANSWER :5

12 int a[3]={2,3,4}; char *p; p=a; p=(char *)((int *)p+1); printf("%d",p);

13 fn(int i) { return ++i; } void main() { clrscr(); int i=10; fn(i); printf("%d",i); getch(); } ANSWER : 10

14 for(int i=0,j=0;i<5,j<25;i++,j++) {} printf ("%d %d ", i,j) ;

ASNWER : 25 25

15 int i,j; i=10; j=sizeof(++i); printf("%d",i); ANSWER :10 20 struct emp { char name[20]; int age; float sal; }; struct emp e = {"tiger"}; printf("\n %d %f",e.age,e.sal); ANSWER : 0 0.0000

getch(); } */ ************************************************************************ /**************************G:\ash\Qpapers\papers\c questions*************** 6:49 PM 5/10/2003 */ #include<stdio.h> #include<conio.h> void main() { clrscr(); /* 3 char *s="\12345s\n"; printf("%d",sizeof(s)); 4

//ANSWER: 2

unsigned i=1; // unsigned char k= -1 => k=255; signed j=-1; // char k= -1 => k=65535

// unsigned or signed int k= -1 =>k=65535 if(i<j) printf("less"); else if(i>j) printf("greater"); else //ANSWER : LESS if(i==j) printf("equal");

5 float j; //printf("%f",j); j=1000*1000; printf("%f",j);

//ANSWER :16960.000000 // WHEN 100*100 GIVES 10000.000000

12 */ int count=10,*temp,sum=0; temp=&count; printf("%d %d ",*temp,count,sum); *temp=20; printf("%d %d ",*temp,count,sum); temp=&sum; printf("%d %d ",*temp,count,sum); *temp=count; printf("%d %d %d ",count,*temp,sum); getch(); } ************************************************************************ #include<stdio.h> #include<conio.h> #include <string.h> void main() { clrscr();

/* 1 int sum,count; void main(void) {

clrscr(); for(count=5;sum+=--count;) printf("%d",sum);

//Prints 4791010974

2 int fno() { static int f1=1,f2=1,f3; return(f3=f1+f2,f1=f2,f2=f3); } 3. void main(){clrscr(); int i; for(i=2;i<=7;i++) printf("%5d",fno());getch();}

4 int x; x = 0; if (x=0) printf ("Value of x is 0"); else printf ("Value of x is not 0"); //ANSWER :X IS NOT 0

5 int foo(char *); void main (void) { char arr[100] = {"Welcome to Mistral"}; foo (arr); } foo (char *x) { printf ("%d\t",strlen (x)); printf ("%d\t",sizeof(x)); return 0; }

// answer :18

display() { printf ("\n Hello World"); return 0; } void main (void) { int (* func_ptr) (); func_ptr = display; printf ("\n %u",func_ptr); (* func_ptr) (); }

//answer : HELLO WORLD

7 int i = 0; char ch = 'A'; do putchar (ch); while(i++ < 5 || ++ch <= 'F');

11 int i; static int k; if(k=='0') printf("one"); else if(k== 48) printf("two"); else printf("three");

//answer :three

12 enum sub { chemistry, maths, physics }; struct result { char name[30]; enum sub sc; }; struct result my_res; strcpy (my_res.name,"Patrick"); my_res.sc=physics; printf("name: %s\n",my_res.name); printf("pass in subject: %d\n",my_res.sc);

// patrick 2

13 printf("%s",_FILE_); printf("%d",_LINE_); //undefined symbol

14 void swap (int x, int y, int t) { t = x; x = y; y = t; printf ("x inside swap: %d\t y inside swap : %d\n",x,y); } void main(void) { clrscr(); int x; int y; int t; x = 99; y = 100; swap (x,y,t); printf ("x inside main:%d\t y inside main: %d",x,y);

16 char *p = "MISTRAL"; printf ("%c\t", *(++p)); p -=1; printf ("%c\t", *(p++));

// I

17 struct my_struct { int p:1; int q:1; int r:6; int s:2; }; struct my_struct bigstruct; struct my_struct1 { char m:1; //size is 2 1 }; struct my_struct1 smallstruct; void main (void) { clrscr();

printf ("%d %d\n",sizeof (bigstruct),sizeof (smallstruct));

19 #define SQR(x) (x*x) b+2*b+2 void main(void) { clrscr(); int a,b=3; a = SQR(b+2); printf("%d",a);

//11

20 int mat [5][5],i,j; int *p; p =&mat [0][0]; for (i=0;i<5;i++) for (j=0;j<5;j++) mat[i][j] = i+j; printf ("%d\t", sizeof(mat)); i=4;j=5; printf( "%d", *(p+ffi+j));

23 char *p = "Bangalore"; #if 0 printf ("%s", p); #endif //doesnot print anything

24 float y; int x; y = *(float *)&x;

getch();}

***************************************************************************

/*****************G:\ash\Qpapers\papers\c questions\ramco*******************/ #include<stdio.h> #include<conio.h> #include<process.h> void main(void){clrscr(); /* 10) int x; int Modify_value() { return (x+=10); } int change_value() { return(x+=1); } void main() { clrscr(); x++; change_value(); x++; Modify_value(); printf("First output: %d\n",x); x++; change_value(); printf("Second Output : %d\n",x); Modify_value(); printf("Third Output : %d\n",x);

12 int a=0; if(a=0) printf("Ramco1 Systems\n"); printf("Ramco Systems\n");

14 void main(void); int printf(const char*,...);

void main(void) { clrscr(); int i=100,j=10,k=20; int sum; float ave; char myformat[]="ave=%.2f"; sum=i+j+k; ave=sum/3.0; printf(myformat,ave);

15 int a[10]; printf("%d",((a+9) + (a+1)));

16 struct s{ int x; float y; }s1={25,45.00}; union u{ int x; float y; } u1; struct s2; u1= (union u)s1; printf("%d and %f",u1.x,u1.y);

// cannot type cast

17 unsigned int c; unsigned x=0x3; scanf("%u",&c); switch(c&x) { case 3: printf("Hello!\t"); case 2: printf("Welcome\t"); case 1: printf("To All\t"); default:printf("\n"); }

// welcome to all

18 int fn(void);

void print(int,int(*)()); int i=10; void main(void) { int i=20; print(i,fn); getch(); } void print(int i,int (*fn1)()) { printf("%d\n",(*fn1)()); } int fn(void) { return(i-=5); }

19 char numbers[5][6]={"Zero","One","Two","Three","Four"}; // four is zint bags[5] ={20,5,20,3,20}; printf("%s is %c",&numbers[4][0],numbers[0][0]);

20 int bags[5]={20,5,20,3,20}; void main(void) { clrscr(); int pos=5,*next(); *next()=pos; printf("%d %d %d",pos,*next(),bags[0]); getch(); } int *next() { int i; for(i=0;i<5;i++) if (bags[i]==20) return(bags+i); printf("Error!"); exit(0); }

// 5

20

21 int y,z; int x=y=z=10; int f=x; float ans=0.0;

f *=x*y; ans=x/3.0+y/3; printf("%d %.2f",f,ans);

// 1000 6.33

22 double dbl=20.4530,d=4.5710,dblvar3; double dbln(void); dblvar3=dbln(); printf("%.2f\t%.2f\t%.2f\n",dbl,d,dblvar3); getch(); } double dbln(void) { double dblvar3,dbl,d; dbl=dblvar3=4.5; printf("%ld",d); return(dbl+d+dblvar3); }

23 static int i=5; void main(void) { int sum=0; do { sum+=(1/i); printf("%d",sum); }while(0<i--); getch(); }

24 int swap(int,int); int oldvar=25,newvar=-25; swap(oldvar,newvar); printf("Numbers are %d\t%d",newvar,oldvar); getch(); } int swap(int oldval,int newval) { int tempval=oldval; oldval=newval; newval=tempval;

25 int i=100,j=20; i+=j; i*=j; printf("%d\t%d\n",i,j);

26 void main(void); int newval(int); void main(void) { clrscr(); int ia[]={12,24,45,0}; int i; int sum=0; for(i=0;ia[i];i++) { sum+=newval(ia[i]); printf("%d\t ",sum); } //printf("Sum= %d",sum); getch(); } int newval(int x) { static int div=1; return(x/div++); } ans : 39

28 void main(void) { void pa(int *a,int n); int arr[5]={5,4,3,2,1}; pa(arr,5); getch(); } void pa(int *a,int n) { int i; for(i=0;i<n;i++) printf("%d\n",*(a++)+i);

// 5

5 5

29 void main(void); void print(void) { print(); } void f1(void) { printf("\nf1():"); }

31 static int i=50; int print(int i); void main(void) { static int i=100; clrscr(); while(print(i)) { printf("%d\n",i); i--; } getch(); } int print(int x) { static int i=2; return(i--); }

33 void main(void); const int k=100; void main(void) { int a[100]; int sum=0; for(k=0;k<100;k++) *(a+k)=k; sum+=a[--k]; printf("%d",sum); }

deshaw ------15 int i=10; printf("%d %d %d ",++i,i++,++i); 13,11,11

16 */ int a=10,b=20; a>=5?b=100:b=200; printf("%d\n",b);

getch();} ************************************************************************

/*******************scope of variables ********************** 1. when a varible is globally declared the value will be always = 0 2. variable scope depends on the function 3. when a variable is declared static its value is 0 */ #include<stdio.h> #include<conio.h> extern int i=1; void test() { printf("%d",i); } void main() { clrscr(); static int i; printf("%d",i);

test(); getch(); } **************************************************************************

1. Question: The C language terminator is (a) semicolon (b) colon (c) period (d) exclamation mark Ans: 1 2. Question: Which of the following makes the statement incorrect? Description: A compound statement is: (a) a set of simple statements (b) demarcated on either side by curly brackets (c) can be used in place of simple statement (d) a C function is not a compound statement. Ans: 2 3. Question: Which of the following statements on C functions is true? (a) Need not return any value (b) Should always return an integer (c) Should always return a float (d) Should always return more than one value Ans: 1 4. Question: The function main( ) must be written (a) as the first function in the program (b) as the second function in the program (c) as the last function in the program (d) any where in the program Ans: 4 5. Question: is true? (a) Its type (b) They are (c) They are (d) They are Ans: 3 Which of the following about automatic variables within a function must be declared before using the variable not local not initialized to zero global

6. Question: Pick a single statement equivalent to the following two statements. Description: x = sqr(a); return(x); (a) return(sqr(a)); (b) printf("sqr(a)"); (c) return(a*a*a); (d) printf("%d",sqr(a)); Ans: 1 7. Question: Which of the following about C comments is incorrect?

(a) Comments can go over multiple lines (b) Comments can start any where in the line (c) A line can contain comments with out any language statements (d) Comments can occur within comments Ans: 4 8. Question: What is the final value of y, in the following code? Description: x = 7; y = 0; if ( x = 6 ) y = 7; else y = 1; (a) 7 (b) 0 (c) 1 (d) 6 Ans: 1 9. Question: Read the function Description: conv ( int t ) { int u; u = 5/9 * (t - 32); return(u); } (a) 15 (b) 0 (c) 16.1 (d) 29 Ans: 2 conv( ) given below and say what is returned.

10. Question: Which of the following represents the statement given? Description: Either x is in the range of 10 and 50 or y is zero (a) x >= 10 && x <= 50 || y ==0 (b) x < 50 (c) y != 10 && x >= 50 (d) None of the above Ans: 1 11. (a) (b) (c) Question: Which of the following is not an infinite loop? while(1) { } for ( ; ; ) { } x = 0; do{ /*x unaltered within the loop*/

}while (x ==0); (d) # define TRUE 0 while (TRUE) { } Ans: 4 12. Question: What does the following piece of code output? Description: func ( int i ) { if ( i % 2 ) return 0; else return 1; } main ( )

{ int i = 3; i = func( i ); i = func( i ); printf("%d",i ); } (a) 3 (b) 1 (c) 0 (d) 2 Ans: 2 13. Question: How does the C compiler interpret the following two statements? Description: p = p + x; q = q + y; (a) p=p+x; q=q+y (b) p=p+xq=q+y (c) p=p+xq; q=q+y (d) p=p+x/q=q+y 14. Question: What is the data type of the following: Description: '9' (a) int (b) char (c) string (d) float Ans: 2 15. Question: What is the data type of the following: Description: "1e-02" (a) int (b) char (c) string (d) float Ans: 3 16. Question: What is the data type of the following: Description: 10e05 (a) int (b) char (c) string (d) float Ans: 4 17. Question: What is the data type of the following: Description: 15 (a) int (b) char (c) string (d) float Ans: 1 18. Question: If initially x is 200, what is its value after executing this code ? Description: # define MAX 100 # define MIN 100

main ( ) { if ( x > MAX ) x = 1; else if ( x < MIN ) x = -1; x = 50; } (a) 200 (b) 1 (c) -1 (d) 50 Ans: 4 19. Question: What is the value of l ? Description: A memory of 20 bytes is allocated to a string declared as char *s and then the f ollowing two statements are executed: s = "Entrance" l = strlen(s); (a) 20 (b) 8 (c) 9 (d) 21 Ans: 2 20. Question: To access the 6th element of the array which of the following is i ncorrect? Description: int a[50]; int *pa; pa = a; (a) *(a+5) (b) a[5] (c) pa[5] (d) *(*pa + 5} Ans: 4 21. Question: What does the given code print? Description: struct num nam{ int no; char name[25]; }; struct num nam n1[] = {{12,"Fred"},{15,"Martin"},{8,"Peter"},{11,Nicholas"}}; printf("%d,%d",n1[2].no,(*(n1 + 2).no + 1)); (a) 8,9 (b) 9,9 (c) 8,8 (d) 8,unpredictable value Ans: 1 22. (a) (b) (c) (d) Question: Identify the incorrect expression a = b = 3 = 4; a = b = c = d = 0; float a = int b = 3.5; int a; float b; a = b = 3.5;

Ans: 1 23. Question: Regarding the scope of the variables, identify the incorrect state ment: (a) Automatic variables are automatically initialized to 0 (b) Static variables are automatically initialized to 0 (c) The address of a register variable is not accessible (d) Static variables cannot be initialized with any expression Ans: 1 24. Question: The given statement is equivalent to which of the following? Description: cond 1?cond 2?cond 3?:exp 1:exp 2:exp 3:exp 4; (a)if cond 1 exp 1; else if cond 2 exp 2; else if cond 3 exp 3; else exp 4; (b)if cond 1 if cond 2 if cond 3 exp 1; else exp 2; else exp 3; else exp 4; (c)if cond 1 && cond 2 && cond 3 exp 1|exp 2|exp 3|exp 4; (d)if cond 3 exp 1; else if cond 2 exp 2; else if cond 3 exp 3; else exp 4; Ans: 2 25. Question: The operator for exponentiation is (a) ** (b) ^ (c) % (d) not available Ans: 4 26. Question: Which of the following is invalid? (a) a += b (b) a *= b (c) a >>= b (d) a **= b Ans: 4 27. Question: What is y value of the code if input x = 10? Description: y = 5; if (x ==10) else if (x ==9) else y = 8; (a)9 (b)8 (c)6 (d)None of the above Ans: 4 28. Question: What does the given code do? Description: fn ( int n, int p, int r) { static int a = p;

switch (n) { case 4: a += case 3: a += case 2: a += case 1: a += } } (a) computes (b) computes (c) computes (d) computes Ans: 2

a*r; a*r; a*r; a*r; simple interest for one year amount on compound interest for 1 to 4 years simple interest for four year compound interest for 1 year

29. Question: How many times does the loop occurs? Description: a = 0; while ( a < 5 ) printf("%d\n",a++); (a) Infinite (b) 5 (c) 4 (d) 6 Ans: 2 30. Question: How many times does the loop iterate? Description: for ( i = 0 ; i = 10 ; i += 2 ) printf("Hi\n"); (a)10 (b) 2 (c) 5 (d) None of the above Ans: 4 31. Question: Which of the following makes the statement incorrect? Description: A recursive function (a) calls itself (b) is equivalent to a loop (c) has a termination condition (d) does not have a return value at all Ans: 4 32. Question: Which (a) while ( expn 1) (b) while ( !expn 1 (c) do { if ( expn (d) while ( !expn 2 Ans: 3 of the following loop are exit if expn 2 { if ( expn 2 ) continue; } ) { if ( expn 2 ) continue; } 1 ) continue; } while ( expn 2 ); ) { if ( expn 1 ) continue; } becomes false?

33. Question: How many times will the loop get executed? Description: main ( ) { unsigned int i = 10; while ( i >= 0 ) { printf("%u",i) i--; } }

(a) 10 (b) 9 (c) 11 (d) infinite Ans: 4 34. Question: Pick the odd one out. (a) malloc() (b) calloc() (c) free() (d) realloc() Ans: 4 35. Question: The value of b[-1] is: Description: main ( ) { int a[5] = { 1,3,6,7,0 }; int *b; b = &a[2]; } (a) 1 (b) 3 (c) -6 (d) None of the above Ans: 2

36. Question: What is the output of the given program? Description: # define prod ( a , b ) = a * b main ( ) { int x = 2; int y = 3; printf("%d",prod (x+2,y-10) ); } (a) -28 (b) +28 (c) 11 (d) None of the above Ans: 4 37. Question: If n = 2, what is the value of Description: int n,sum = 1; switch (n) { case 2 : sum = sum + 2; case 3 : sum *= 2; break; default : sum = 0; } (a) 0 (b) 6 (c) 3 (d) None of these Ans: 2 sum

38. Question: Identify the incorrect Description: 1. if ( c = 1 ) 2. if ( c != 3 ) 3. if ( a < b ) then 4. if ( c == 1 ) (a) 1 only (b) 1&3 (c) 3 only (d) All of the above Ans: 3

if

statement.

39. Question: The format specified for hexadecimal is (a) %d (b) %o (c) %x (d) %u Ans: 3 40. Question: Find the output of the given program Description: main ( ) { int *p, x = 5; p=&x printf("%d",++*p); } (a) 5 (b) 6 (c) 0 (d) None of the above Ans: 2 41. Question: The final value of x is: Description: int func(int n) { static sum = 0; sum = sum+n; return(sum); } main ( ) { int i = 3, x; while ( i > 0 ) { x = func( i ); i--; } } (a) 6 (b) 2 (c) 1 (d) 3 Ans: 1 42. Question: int *a[5] refers to: (a) array of integer pointers (b) pointer to an integer array (c) pointer to a pointer (d) None of the above Ans: 1

43. Question: Which of the given statements is incorrect? (a) typedef struct new{ int n1; char n2; }DATA; (b) typedef struct { int n3; char *n4; }ICE; (c) typedef union { int n5; float n6; }UDT; (d) #typedef union { int n7; float n8; }TUDAT; Ans: 4 44. Question: Which of these is an invalid data name? a) [wd_count] b) wd_count c) w4count d) wdcountabcd Ans: 1 45. Question: What is the value of Description: i = 1; i << 1 % 2 a) 0 b) 1 c) 2 d) 3 Ans: 2 i after the given expression?

46. Question: What is the value of i Description: i = 1; i = (i <<= 1 % 2) a) 0 b) 1 c) 2 d) erroneous syntax Ans: 3 47. Question: What is the value of b? Description: int *a, b; b = 1; a = &b; b = *a + 1 - *a + 3 a) 0 b) 1 c) 4 d) None of the above Ans: 3

after the given expression?

48. Question: Which of the following makes the statement correct?

Description: a) only call b) only call c) both call d) only call Ans: 3

C allows by value by reference by value & reference by value and sometimes call by reference

49. Question: The given statement is: Description: The size of a structure is always equal to the sum of the sizes of its members a) valid b) invalid c) can't say d) None of the above Ans: 1 50. Question: How many x are printed? Description: for (i = 0, j = 10 ; i < j ; i++, j--) printf("x"); a) 10 b) 5 c) 4 d) none Ans: 2 51. Question: What is the output? Description: swap (int i, int j) { int temp; temp = i; i = j; j = temp; } main () { int i = 2, j = 3, k = 1; swap (i, j) printf ("%d %d", i, j); } a) 1, 4 b) 2, 3 c) 1, 3 d) 2, 4 Ans: 2 52. Question: What is the value of *p? Description: int i, b[] = {1, 2, 3, 4, 5}, *p; p = b; ++*p; p += 2; a) 2 b) 3 c) 4 d) 5 Ans: 2 53. Question: What is the value of (p - (&p - 2))? a) 0 b) 2 c) 3 d) None of the above

Ans: 4 54. Question: What does b stand for in the given expression? Description: x = fopen (b, c); a) pointer to a character array which contains the filename b) filename within double quotes c) any one of the above d) None of the above Ans: 3 55. Question: For x = malloc (y) , which of the following statements is correct? a) x is the size of the memory allocated b) y points to the memory allocated c) x points to the memory allocated d) none of the above Ans: 3 56. Question: Which is the valid declaration? a) #typedef struct { int i;}in; b) typedef struct in {int i;}; c) #typedef struct int {int i;}; d) typedef struct {int i;} int; Ans: 2 57. Question: What is the output? Description: union { int no; char ch; } u; u.ch = '2'; u.no = 0; printf ("%d", u.ch); a) 2 b) 0 c) NULL character d) None of the above Ans: 2 58. Question: Which of these are valid declarations? Description: i) union { int i; int j; }; ii) union u_tag { int i; int j; }; iii) union { int i; int j; FILE k; }; iv) union { int i; int j; } u; a) all correct b) i, ii, iv

c) ii & iv d) None of the above Ans: 2 59. Question: p and q are pointers to the same type of data items. Which of these are valid? Description: i) *(p + q) ii) *(p - q) iii) *p - *q a) all b) i and ii c) iii is valid sometimes d) None of the above Ans: 1 60. Question: Which of the given statements are true? Description: i) pointers can be added ii) pointers can be subtracted iii) integers can be added to pointers a) only i b) only iii c) both i & iii d) i,ii & iii Ans: 4 61. Question: What is the output? Description: int i = 20; printf ("%x", i); a) x14 b) 14 c) 20 d) None of the above Ans: 2 62. Question: What is the output? Description: main ( ) { char *name = "name"; change (name); printf ("%s", name); } change (char *name) { char *nm = "newname"; name = nm; } a) name b) newname c) name = nm not valid d) function call invalid Ans: 1 63. Question: What is the output? Description: char name[] = {'n', 'a', 'm', 'e'}; printf ("name = \n%s", name);

a) name = name b) name = followed by junk characters c) name = name d) None of the above Ans: 3 64. Question: What is the final value of b? Description: int a = 1, b = 2; if (a = 0) b = 0; else b *= 10; a) 0 b) 20 c) 2 d) None of the above Ans: 1 65. Question: What is the value of x after the given statements? Description: int x = 2, y = 2, z = 1; if (x = y%2) else a) 0 b) 2 c) 1 d) None of the above Ans: 1 66. Question: What is the output if initially n = -24? Description: printd (int n) { if (n < 0) { printf ("-"); n = -n; } if (n % 10) printf ("%d", n); else printf ("%d", n/10); printf ("%d", n); } a) -24 b) 24 c) -2424 d) -224 Ans: 3 67. Question: If the input stream contains "4.2 3 2.3 ..." what will x and y contain after scanf? Description: float x, y, z; scanf ("%f %f", &x, &y); a) 4.2, 3.0 b) 4.2, 2.3 c) 4.2, 32.3 d) None of the above Ans: 1

68. Question: What is the output? Description: #define max(a,b) (a>b?b:a) #define squre(x) x*x int i = 2, j = 3, k = 1; printf ("%d %d", max(i,j), squre(k)); a) 32 b) 21 c) 31 d) 13 Ans: 2 69. Question: Which are valid references? Description: struct adr { char *name; char *city; int zip; }; struct adr *adradr; i) adr->name ii) adradr->name iii) adr.zip iv) adradr.zip i ii i & iii ii & iv is invoked as

a) only b) only c) both d) both Ans: 4

70. Question: What is the output if the given program prog.c prog arg1 ? Description: main (x, y) int x, char *y[]; { printf ("%d %s", x, y[1]); } a) 1 prog b) 1 arg1 c) 2 prog d) 2 arg1 Ans: 2

71. Question: Which of s, t and u are available to a function present in another file? Description: extern int s; global int t; static int u; main ( ) { } a) only s b) s & t c) s, t & u d) None of the above Ans: 1

72. Question: For which of the functions is Description: main ( ) { } int a; f1 ( ) { } f2 ( ) { } a) All of them b) only f2 c) only f1 d) both f1 and f2 Ans: 1 73. Question: What is the value of a Description: int a = 'a'; char b = b , c = c ; main ( ) { mixup (a, b, &c); } mixup (int p1, char *p2, char **p3) { int *temp; temp = &p1; p1 = p2; p2 = temp; } a) 97 b) 98 c) 99 d) None of the above Ans: 1 74. Question: What is the value of b Description: int a = 'a'; char b = b , c = c ; main ( ) { mixup (a, b, &c); } mixup (int p1, char *p2, char **p3) { int *temp; temp = &p1; p1 = p2; p2 = temp; } a) a b) b c) c d) None of the above Ans: 2 75. Question: What is the output? Description: main () { char s[] = "T.C.S", *A; print(s); } print (char *p) { while (*p != '\0') { after

a available?

mixup ?

after

mixup ?

if (*p != . ) printf ("%c", *p); p++; } } a) T.C.S b) TCS c) . . d) None of the above Ans: 2 76. Question: If the input is "1a1b1cE", what is the output? Description: main ( ) { int ones, twos, threes, others; int c; ones = twos = threes = others = 0; while ((c = getchar ()) != E ) { switch (c) { case '1': ++ones; case '2': ++twos; case '3': ++threes; break; default: ++others; break; } } printf ("%d%d", ones, others); } a) 13 b) 23 c) 33 d) 31 Ans: 3 77. Question: What will the output be if x = 1234? Description: void output (int x) { if (x != 0) { output(x / 16); putchar("0123456789ABCDEF"[x % 16]); } else putchar('\n'); } a) 1234 b) 3C1 c) 4D2 d) Will not compile Ans: 3 78. Question: What is the output? Description: main( ) { int a=1, b=2, c=3, *pointer; pointer = &c;

a = c/*pointer; b = c; printf ("a=%d b=%d",a,b); } a) 1 3 b) 3 3 c) 3 2 d) Error Ans: 4 79. Question: What is the output? Description: #define scanf "%s is a string" main() { printf(scanf,scanf); } a) scanf is a string b) %s is a string c) %s is a string is a string d) None of the above Ans: 3 80. Question: What is the output? Description: enum mode {green, red, orange, blue, white}; main ( ) { int a = green + 1; printf("%d,%d,%d",a,green,red); } a) 2,1,3 b) 2,1,2 c) 1,0,1 d) None of the above Ans: 3 ***************************************************************************

You might also like