| Other C Code Interview Questions |
| |
| Question | Asked @ | Answers |
| |
| Is the following code legal?
struct a
{
int x;
struct a b;
} | | 1 |
| Find the largest number in a binary tree | Infosys | 4 |
| main()
{
main();
} | | 1 |
| There were 10 records stored in “somefile.dat” but the
following program printed 11 names. What went wrong?
void main()
{
struct student
{
char name[30], rollno[6];
}stud;
FILE *fp = fopen(“somefile.dat”,”r”);
while(!feof(fp))
{
fread(&stud, sizeof(stud), 1 , fp);
puts(stud.name);
}
} | | 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()
{
clrscr();
}
clrscr(); | | 1 |
| 1. const char *a;
2. char* const a;
3. char const *a;
-Differentiate the above declarations. | | 2 |
| Write out a function that prints out all the permutations of
a string.
For example, abc would give you abc, acb, bac, bca, cab,
cba. You can assume that all the characters will be unique. | Microsoft | 4 |
| 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 |
| Program to find the largest sum of contiguous integers in
the array. O(n) | | 7 |
| #define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
} | | 1 |
| Is the following code legal?
struct a
{
int x;
struct a *b;
} | | 1 |
| void pascal f(int i,int j,int k)
{
printf(“%d %d %d”,i, j, k);
}
void cdecl f(int i,int j,int k)
{
printf(“%d %d %d”,i, j, k);
}
main()
{
int i=10;
f(i++,i++,i++);
printf(" %d\n",i);
i=10;
f(i++,i++,i++);
printf(" %d",i);
} | | 1 |
| How do you write a program which produces its own source
code as its output?
| | 7 |
| main()
{
41printf("%p",main);
}8 | | 1 |
| main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
} | | 1 |
| Write a routine that prints out a 2-D array in spiral order | Microsoft | 2 |
| How to access command-line arguments? | | 4 |
| main()
{
extern out;
printf("%d", out);
}
int out=100; | | 1 |
| main()
{
int i;
clrscr();
printf("%d", &i)+1;
scanf("%d", i)-1;
}
a. Runtime error.
b. Runtime error. Access violation.
c. Compile error. Illegal syntax
d. None of the above | HCL | 1 |
| |
| For more C Code Interview Questions Click Here |