| Other C Code Interview Questions |
| | | Question | Asked @ | Answers | | | | main()
{
char str1[] = {s,o,m,e};
char str2[] = {s,o,m,e,\0};
while (strcmp(str1,str2))
printf(Strings are not equal\n);
} | | 1 | | main()
{
printf("%d, %d", sizeof('c'), sizeof(100));
}
a. 2, 2
b. 2, 100
c. 4, 100
d. 4, 4 | HCL | 3 | | struct aaa{
struct aaa *prev;
int i;
struct aaa *next;
};
main()
{
struct aaa abc,def,ghi,jkl;
int x=100;
abc.i=0;abc.prev=&jkl;
abc.next=&def;
def.i=1;def.prev=&abc;def.next=&ghi;
ghi.i=2;ghi.prev=&def;
ghi.next=&jkl;
jkl.i=3;jkl.prev=&ghi;jkl.next=&abc;
x=abc.next->next->prev->next->i;
printf("%d",x);
} | | 1 | | union u
{
struct st
{
int i : 4;
int j : 4;
int k : 4;
int l;
}st;
int i;
}u;
main()
{
u.i = 100;
printf("%d, %d, %d",u.i, u.st.i, u.st.l);
}
a. 4, 4, 0
b. 0, 0, 0
c. 100, 4, 0
d. 40, 4, 0 | HCL | 1 | | Is the following code legal?
typedef struct a
{
int x;
aType *b;
}aType | | 1 | | Give a oneline C expression to test whether a number is a
power of 2?
| Motorola | 16 | | typedef struct error{int warning, error, exception;}error;
main()
{
error g1;
g1.error =1;
printf("%d",g1.error);
} | | 1 | | Which version do you prefer of the following two,
1) printf(%s,str); // or the more curt one
2) printf(str); | | 1 | | #include<stdio.h>
main()
{
struct xx
{
int x=3;
char name[]="hello";
};
struct xx *s=malloc(sizeof(struct xx));
printf("%d",s->x);
printf("%s",s->name);
} | | 1 | | What is "far" and "near" pointers in "c"...? | | 3 | | main()
{
char *p = ayqm;
printf(%c,++*(p++));
} | TCS | 2 | | Write a routine that prints out a 2-D array in spiral order | Microsoft | 2 | | main()
{
char *p = ayqm;
char c;
c = ++*p++;
printf(%c,c);
} | | 1 | | String reverse with time complexity of n/2 with out using
temporary variable. | NetApp | 8 | | main()
{
int i=5;
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i);
} | | 1 | | Write a routine to draw a circle (x ** 2 + y ** 2 = r ** 2)
without making use of any floating point computations at all. | Microsoft | 2 | | void main()
{
static int i=i++, j=j++, k=k++;
printf(i = %d j = %d k = %d, i, j, k);
} | | 1 | | int i=10;
main()
{
extern int i;
{
int i=20;
{
const volatile unsigned i=30;
printf("%d",i);
}
printf("%d",i);
}
printf("%d",i);
} | | 1 | | main()
{
printf("%x",-1<<4);
} | | 1 | | main()
{
printf("%d", out);
}
int out=100; | | 1 | | | | For more C Code Interview Questions Click Here |
|