Friday, November 25, 2011

Test your C Programming skills Part 4






Q1. How scanf will execute?
main(){

   char name[10],s[12];
   scanf(" \"%[^\"]\"",s);

}

Ans:
First it checks for the leading white space and discards it.Then it matches
with a quotation mark and then it reads all character upto another quotation mark.


Q2. What will be the position of the file marker?

a) fseek(ptr,0,SEEK_SET);

b) fseek(ptr,0,SEEK_CUR);

Ans:


Q3. What is the problem with the following code segment?

while ((fgets(receiving array,50,file_ptr)) != EOF)

Ans:


Q4. Find the o/p:
main(){

   char *cptr,c;
   void *vptr,v;

   c=10; v=0;
   cptr=&c; vptr=&v;

   printf("%c%v",c,v);

}

Ans:



Q5. Find the o/p:
#define max 5

#define int arr1[max]

main(){

   typedef char arr2[max];
   arr1 list={0,1,2,3,4};

   arr2 name="name";

   printf("%d %s",list[0],name);

}
Ans:


Q6. Find the o/p:
int i=10;

main() {

   extern int i; {

   int i=20;{
     int i=30;
     printf("%d",i);

   }

   printf("%d",i);

   }

   printf("%d",i);

}
Ans:


Q7. Find the o/p:
main(){

   int *j;{
     int i=10;
     j=&i;
   }

   printf("%d",*j);

}

Ans:


Q8. Find the o/p:
# include < stdio.h >
main() {

const int i=4;

float j;

   j = ++i;

   printf("%d %f", i,++j);

}
Ans:


Q9. Find the o/p:
main() {

int i=_l_abc(10);

   printf("%d\n",--i);

}

int _l_abc(int i) {

return(i++);

}

Ans:


Q10. Find the o/p of this:
main(int argc, char **argv) {

   printf("enter the character");
   getchar();

   sum(argv[1],argv[2]);

}

sum(num1,num2)int num1,num2; {

return num1+num2;

}
Ans:


Q11. Find the o/p:
int one_d[]={1,2,3};

main(){

int *ptr;

   ptr=one_d;
   ptr+=3;

   printf("%d",*ptr);
}

Ans:


Q12. Find the o/p:
main(){

FILE *ptr;
char i;

   ptr=fopen("zzz.c","r");
   while((i=fgetch(ptr))!=EOF)
      printf("%c",i);

}

Ans:


Q13.Find the o/p:
int i;

main(){

int t;

   for ( t=4;scanf("%d",&i)-t;printf("%d\n",i))
      printf("%d--",t--);

}

// If the inputs are 0,1,2,3 find the o/p

Ans:











No comments:

Post a Comment