predict output:
struct A
{
int a;
int b;
};
struct A var;
var.a = 1;
main()
{
var.a = 2;
printf("%d",var.a);
}
predict output:
int arr[] = {1,2,3,4,5};
int *p;
int **q;
p = arr;
q = &p;
p += 2;
printf("%d %d %d ",0[*q], *(p+ p[-2]), (1[*q]-3)[p]);
/*assume 32 bit compiler*/
predict output: case1: keep commented last line
case2: remove last line comment
main()
{
char *arr[] = {"shani","from","IIITA","to","Aricent"};
char **p;
char ***q;
p = arr;
q = &p;
p = p + 4;
printf("%d %d %s\n",sizeof(arr[0]),sizeof(arr),(-2)[*q]);
//printf(" %s",&(0[*p] = 'a'));
}
int x = 2;
void fun()
{
static int x =0;
x += 10;
}
main()
{
printf("%d ",x);
fun();
printf("%d ",x);
}
void f2(int *a,int *b)
{
*a ^= *b ^= *a ^= *b;
printf("%d, %d",*a,*b);
}
void f1(int *a, void (*p)(int *a,int *b))
{
int b = 20;
p(a,&b);
}
int main()
{
int a = 10;
void (*ptr)(int *,void(*)(int *,int *)) = f1;
ptr(&a,f2);
}
/*suppose 32 bit compiler and no pragma is used*/
predict output:
struct X
{
int a:12
char b:7;
int c:12;
};
main()
{
printf("%d",sizeof(struct X));
}
what is output
enum {F,T};
main()
{
int i=1;
do
{
printf("%d\n",i);
i++;
if(i < 15)
continue;
}while(F);
}
#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};
int main()
{
int d;
for(d=-1;d <= (TOTAL_ELEMENTS-2);d++)
printf("%d ",array[d+1]);
return 0;
}
output:
int main(int x )
{
static int a = 10;
if(a)
main(--a);
printf("%d ",a);
return 0;
}
what will be output in different scenario:
1. both lines r kept commented
2. comment 1 is uncommented 2nd remain unchanged
3 comment 2 is uncommented while 1st is commented
4. both comment 1&2 r uncommented
let input is: shani#
int main()
{
char ch = '#';
FILE *fp1 = stdin,*fp2 = stdout;
//fclose(fp1) comment 1
//fclose(fp2) comment 2
while((ch = getc(fp1)) != '#')
{
putc(ch,fp2);
}
}