Thursday, May 26, 2011

Test your C Programming skills Part 1






Q1. Find the o/p:
main()
{
    char *ptr="hello";
    char ary[]="world";

printf("PTR: &ptr=%x, ptr=%x, *ptr=%x, ptr[0]=%x\n", &ptr,ptr, *ptr, ptr[0]);
printf("ARY: &ary=%x,ary=%x, *ary=%x, ary[0]=%x\n", &ary, ary, *ary, ary[0]);
}

Ans:
PTR: &ptr=bfb86990, ptr=8048524, *ptr=68, ptr[0]=68
ARY: &ary=bfb8698a,ary=bfb8698a, *ary=77, ary[0]=77


Q2. Find the o/p:
main()
{
    struct node {
        char a;
        int b; 
        short c;
        struct node next;
    }n1;   

printf("Ans1:%d\n", sizeof(n1));

return 0;
}

Ans:


Q3. Find the o/p:
main()
{
    struct node {
        char a;
        int b; 
        short c;
        struct node *next;
    }n1;   

printf("Ans1:\n\t node=%x\n \t node+2=%x\n", (char *)&n1, (char *)&n1+2);
printf("Ans2:%d\n", sizeof(n1));

return 0;
}
Ans:


Q4. What is the difference between fopen() and open()? When do you choose to use one over the other?

Ans:



Q5. Find the o/p:
main()
{
if(!printf("Hello ")){}
else
printf("World!");
}
Ans:


Q6. Find the o/p:
main()
{
struct i{
int a;    //4
double b;    //8
char * c;    //4
char d[7];    //8
short e;    //4
int f;    //4
};
printf("sizeof(i)= %d", sizeof(struct i));
}
Ans:


Q6.1. Find the o/p:
main()
{
struct i{
int a;    //4
double b;    //8
char * c;    //4
char d[3];    //4
short e;    //4
int f;    //4
};
printf("sizeof(i)= %d", sizeof(struct i));
}
Ans:



Q7. Find the o/p:
# include < stdio.h >
void main()
{
printf(NULL) ;
return ;
}
Ans:


Q8. Find the o/p:
# include < stdio.h >
void main()
{
int i = 0;
printf(i) ;
return ;
}
Ans:


Q9. Find the o/p:
#include <stdio.h>
void main()
{
printf("%s",NULL) ;
return ;
}
Ans:


Q10. Find the o/p of this last one:
main()
{
printf("%%",7);
}
Ans:


Q11. How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
Ans:


Q12. What is asmlinkage and what is it's use?
Ans:


Q13. What is output?
main()
{
printf("%x",-1<<4); }


Ans:













No comments:

Post a Comment