| Other C Code Interview Questions |
| |
| Question | Asked @ | Answers |
| |
| #include<stdio.h>
main()
{
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} };
int *p,*q;
p=&a[2][2][2];
*q=***a;
printf("%d----%d",*p,*q);
} | | 1 |
| main()
{
char *a = "Hello ";
char *b = "World";
clrscr();
printf("%s", strcpy(a,b));
}
a. “Hello”
b. “Hello World”
c. “HelloWorld”
d. None of the above | HCL | 1 |
| void main()
{
int *i = 0x400; // i points to the address 400
*i = 0; // set the value of memory location pointed by i;
} | | 1 |
| What is the hidden bug with the following statement?
assert(val++ != 0); | | 1 |
| main()
{
char *p="GOOD";
char a[ ]="GOOD";
printf("\n sizeof(p) = %d, sizeof(*p) = %d, strlen(p) = %d",
sizeof(p), sizeof(*p), strlen(p));
printf("\n sizeof(a) = %d, strlen(a) = %d",
sizeof(a), strlen(a));
} | | 1 |
| void main()
{
int i=10, j=2;
int *ip= &i, *jp = &j;
int k = *ip/*jp;
printf(“%d”,k);
} | | 1 |
| In the following pgm add a stmt in the function fun such
that the address of
'a' gets stored in 'j'.
main(){
int * j;
void fun(int **);
fun(&j);
}
void fun(int **k) {
int a =0;
/* add a stmt here*/
} | | 1 |
| main()
{
char a[4]="HELL";
printf("%s",a);
} | Wipro | 1 |
| main()
{
int c = 5;
printf("%d", main||c);
}
a. 1
b. 5
c. 0
d. none of the above | HCL | 1 |
| Give a very good method to count the number of ones in a 32
bit number.
(caution: looping through testing each bit is not a solution) | Microsoft | 5 |
| main()
{
float i=1.5;
switch(i)
{
case 1: printf("1");
case 2: printf("2");
default : printf("0");
}
} | | 1 |
| Write a function to find the depth of a binary tree. | Adobe | 8 |
| struct Foo
{
char *pName;
};
main()
{
struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
strcpy(obj->pName,"Your Name");
printf("%s", obj->pName);
}
a. Your Name
b. compile error
c. Name
d. Runtime error | HCL | 1 |
| Given an array of size N in which every number is between 1
and N, determine if there are any duplicates in it. You are
allowed to destroy the array if you like. | Microsoft | 15 |
| Given only putchar (no sprintf, itoa, etc.) write a routine
putlong that prints out an unsigned long in decimal. | | 5 |
| Write a routine that prints out a 2-D array in spiral order | Microsoft | 2 |
| main()
{
int i =0;j=0;
if(i && j++)
printf("%d..%d",i++,j);
printf("%d..%d,i,j);
} | | 1 |
| main()
{
if (!(1&&0))
{
printf("OK I am done.");
}
else
{
printf("OK I am gone.");
}
}
a. OK I am done
b. OK I am gone
c. compile error
d. none of the above | HCL | 1 |
| 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 |
| Which version do you prefer of the following two,
1) printf(“%s”,str); // or the more curt one
2) printf(str); | | 1 |
| |
| For more C Code Interview Questions Click Here |