C Language Interview Question

There are many things that you can do ahead of time to prepare for the interviewing process, and move yourself a step above of the competition. Updating your resume and reviewing frequently asked interview questions can be very effective, and goes a long way in getting the most out of your interview.

What will be printed as the result of the operation below:

main()
{
char *ptr = ” Tech Preparation”;
*ptr++; printf(“%s\n”,ptr)
; ptr++;
printf(“%s\n”,ptr);

}

1) ptr++ increments the ptr address to point to the next address. In the previous example, ptr was pointing to the space in the string before C, now it will point to C.

2)*ptr++ gets the value at ptr++, the ptr is indirectly forwarded by one in this case.

3)(*ptr)++ actually increments the value in the ptr location. If *ptr contains a space, then (*ptr)++ will now contain an exclamation mark.

Answer: Tech Preparation

 

What will be printed as the result of the operation below:

main()
{
char s1[]=“Tech”;
char s2[]= “preparation”;
printf(“%s”,s1)
; }


Answer: Tech

 

What will be printed as the result of the operation below:

main()
{
char *p1;
char *p2;

p1=(char *)malloc(25);
p2=(char *)malloc(25);

strcpy(p1,”Tech”);
strcpy(p2,“preparation”);
strcat(p1,p2);

printf(“%s”,p1)
;
}


Answer: Techpreparation

 

The following variable is available in file1.c, who can access it?: static int average;

Answer: all the functions in the file1.c can access the variable.