| Other C Code Interview Questions |
| |
| Question | Asked @ | Answers |
| |
| What is the subtle error in the following code segment?
void fun(int n, int arr[])
{
int *p=0;
int i=0;
while(i++<n)
p = &arr[i];
*p = 0;
} | | 1 |
| #include <stdio.h>
main()
{
char * str = "hello";
char * ptr = str;
char least = 127;
while (*ptr++)
least = (*ptr<least ) ?*ptr :least;
printf("%d",least);
} | | 1 |
| main()
{
char c;
int i = 456;
clrscr();
c = i;
printf("%d", c);
}
a. 456
b. -456
c. random number
d. none of the above | HCL | 1 |
| #define DIM( array, type) sizeof(array)/sizeof(type)
main()
{
int arr[10];
printf(“The dimension of the array is %d”, DIM(arr,
int));
} | | 1 |
| main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c;
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q; }
for(j=0;j<5;j++){
printf(" %d ",*p);
++p; }
} | | 1 |
| #define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
} | | 1 |
| main()
{
int i=3;
switch(i)
{
default:printf("zero");
case 1: printf("one");
break;
case 2:printf("two");
break;
case 3: printf("three");
break;
}
} | | 1 |
| How to swap two variables, without using third variable ? | HCL | 48 |
| main()
{
char *a = "Hello ";
char *b = "World";
clrscr();
printf("%s", strcat(a,b));
}
a. Hello
b. Hello World
c. HelloWorld
d. None of the above | HCL | 1 |
| What are segment and offset addresses? | Infosys | 1 |
| main()
{
int i=4,j=7;
j = j || i++ && printf("YOU CAN");
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 |
| #define FALSE -1
#define TRUE 1
#define NULL 0
main() {
if(NULL)
puts("NULL");
else if(FALSE)
puts("TRUE");
else
puts("FALSE");
} | | 1 |
| #include<stdio.h>
main()
{
const int i=4;
float j;
j = ++i;
printf("%d %f", i,++j);
} | | 1 |
| Given an array of characters which form a sentence of
words, give an efficient algorithm to reverse the order of
the words (not characters) in it.
| Microsoft | 7 |
| main()
{
float i=1.5;
switch(i)
{
case 1: printf("1");
case 2: printf("2");
default : printf("0");
}
} | | 1 |
| main()
{
char *p="hai friends",*p1;
p1=p;
while(*p!='\0') ++*p++;
printf("%s %s",p,p1);
} | | 1 |
| #include"math.h"
void main()
{
printf("Hi everybody");
}
if <stdio.h> will be included then this program will must
compile, but as we know that when we include a header file
in "" then any system defined function find its defination
from all the directrives. So is this code of segment will
compile? If no then why? | | 2 |
| main()
{
char *p;
printf("%d %d ",sizeof(*p),sizeof(p));
} | | 1 |
| 1)
int i=5;
j=i++ + i++ + i++;
printf("%d",j);This code gives the answer 15.But if we
replace the value of the j then anser is different?why?
2)int i=5;
printf("%d",i++ + i++ + i++);
this givs 18. | Infosys | 6 |
| |
| For more C Code Interview Questions Click Here |