| Other C Code Interview Questions |
| |
| Question | Asked @ | Answers |
| |
| main()
{
char *cptr,c;
void *vptr,v;
c=10; v=0;
cptr=&c; vptr=&v;
printf("%c%v",c,v);
} | | 1 |
| struct Foo
{
char *pName;
char *pAddress;
};
main()
{
struct Foo *obj = malloc(sizeof(struct Foo));
clrscr();
obj->pName = malloc(100);
obj->pAddress = malloc(100);
strcpy(obj->pName,"Your Name");
strcpy(obj->pAddress, "Your Address");
free(obj);
printf("%s", obj->pName);
printf("%s", obj->pAddress);
}
a. Your Name, Your Address
b. Your Address, Your Address
c. Your Name Your Name
d. None of the above | HCL | 1 |
| void main()
{
printf(“sizeof (void *) = %d \n“, sizeof( void *));
printf(“sizeof (int *) = %d \n”, sizeof(int *));
printf(“sizeof (double *) = %d \n”, sizeof(double *));
printf(“sizeof(struct unknown *) = %d \n”, sizeof(struct
unknown *));
} | | 1 |
| main()
{
extern out;
printf("%d", out);
}
int out=100; | | 1 |
| int aaa() {printf(“Hi”);}
int bbb(){printf(“hello”);}
iny ccc(){printf(“bye”);}
main()
{
int ( * ptr[3]) ();
ptr[0] = aaa;
ptr[1] = bbb;
ptr[2] =ccc;
ptr[2]();
} | | 1 |
| char *someFun1()
{
char temp[ ] = “string";
return temp;
}
char *someFun2()
{
char temp[ ] = {‘s’, ‘t’,’r’,’i’,’n’,’g’};
return temp;
}
int main()
{
puts(someFun1());
puts(someFun2());
} | | 1 |
| Is this code legal?
int *ptr;
ptr = (int *) 0x400; | | 1 |
| main()
{
char *p;
p="Hello";
printf("%c\n",*&*p);
} | | 1 |
| const int perplexed = 2;
#define perplexed 3
main()
{
#ifdef perplexed
#undef perplexed
#define perplexed 4
#endif
printf("%d",perplexed);
}
a. 0
b. 2
c. 4
d. none of the above | HCL | 1 |
| What is the output for the program given below
typedef enum errorType{warning, error,
exception,}error;
main()
{
error g1;
g1=1;
printf("%d",g1);
} | | 1 |
| main()
{
struct date;
struct student
{
char name[30];
struct date dob;
}stud;
struct date
{
int day,month,year;
};
scanf("%s%d%d%d", stud.rollno, &student.dob.day,
&student.dob.month, &student.dob.year);
} | | 1 |
| main(int argc, char **argv)
{
printf("enter the character");
getchar();
sum(argv[1],argv[2]);
}
sum(num1,num2)
int num1,num2;
{
return num1+num2;
} | | 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 |
| main()
{
int i;
printf("%d",scanf("%d",&i)); // value 10 is given as
input here
} | | 1 |
| Write a prog to accept a given string in any order and flash
error if any of the character is different.
For example : If abc is the input then abc, bca, cba, cab
bac are acceptable, but aac or bcd are unacceptable. | Microsoft | 5 |
| to remove the repeated cahracter from the given caracter
array.
i.e..,
if the input is SSAD
output should of
SAD | Synergy | 6 |
| main()
{
char *p;
p="%d\n";
p++;
p++;
printf(p-2,300);
} | | 1 |
| main()
{
int i=-1;
+i;
printf("i = %d, +i = %d \n",i,+i);
} | | 1 |
| char *someFun()
{
char *temp = “string constant";
return temp;
}
int main()
{
puts(someFun());
} | | 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 |
| |
| For more C Code Interview Questions Click Here |