Friday, November 25, 2011

Test your C Programming skills Part 2







Q1. How would you declare a pointer variable ptr so that it can not be used to modify the string it points to (although ptr itself can be changed to point to some other string)?

Ans:
     char * const ptr = "Hello";


Q2. How are the string literals are processed by compiler?

Ans:


Q3.
int a[25];
int * p = a + 3;

Which one of the following is equivalent to the above code snippet?
a) int a[25];
int *p = &a[3];

b) int a[25];
int * p = &(a + 3);

c) int a[25];
int * p = (&a)[3];

d) int a[25];
int * p = &a[2];

e) int a[25];
int * p = a[3];


Ans:


Q4. How would you declare a constant pointer to a constant string?
Ans:



Q5. Find the o/p:
int divider(double m, double n)
{
     return m/n;
}

main()
{
     printf("%d", divider(10/3);
}


Ans:


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

     struct xx{

          char name[]="hello";

};

     struct xx *s;

     printf("%s",s->name);

}
Ans:


Q7. Find the o/p:
void main()
{
     int const *p=5;
     printf("%d",++(*p));

}
Ans:


Q8. Find the o/p:
# include < stdio.h >
main()
{
     float me = 1.1;
     double you = 1.1;

     if(me==you)
          printf("I love U");

     else
          printf("I hate U");

}

Ans:


Q9. Find the o/p:
#include <stdio.h>
main() {
     static int var = 5;
     printf("%d ",var--);
     if(var)
          main();
}

Ans:


Q10. Find the o/p of this:
main(){

     extern int i;

     i=20;

     printf("%d",i);

}
Ans:


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

     char *p;

     printf("%d %d ",sizeof(*p),sizeof(p));

}
Ans:


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

     char string[]="Hello World";

     display(string);

}

void display(char *string){

     printf("%s",string);

}
Ans:


Q13. What is output?
main(){

     int i=10;

     i=!i>14;

     printf("i=%d",i);

}

Ans:











No comments:

Post a Comment