C Interview Questions And Answers

C FAQS
Previous Home Next

C,C++ Questions with answers, C++ Questions Interview with answers

C,C++ Questions

Questions 31 Find the output for the following C program
#include<stdio.h>
main()
{
char *p1;
char *p2;
p1=(char *) malloc(25);
p2=(char *) malloc(25);
strcpy(p1,"Ramco");
strcpy(p2,"Systems");
strcat(p1,p2);
printf("%s",p1);
}
 Ans. RamcoSystems

Questions 32.  Find the output for the following C program given that
[1]. The following variable is available in file1.c
static int average_float;


Ans. All the functions in the file1.c can access the variable

Questions 33.
Find the output for the following C program
# define TRUE 0
some code
while(TRUE)
{
some code
}
Ans. This won't go into the loop as TRUE is defined as 0

Questions 34.
struct list{
       int x;
      struct list *next;
      }*head;

        the struct head.x =100

       Is the above assignment to pointer is correct or wrong ?

Ans. Wrong

Questions 35.What is the output of the following ?

      int i;
      i=1;
      i=i+2*i++;
      printf(%d,i);

Ans. 4

Questions 36.

FILE *fp1,*fp2;
     
      fp1=fopen("one","w")
      fp2=fopen("one","w")
      fputc('A',fp1)
      fputc('B',fp2)
      fclose(fp1)
      fclose(fp2)
     }

     Find the Error, If Any?

Ans. no error. But It will over writes on same file.

What are the output(s) for the following ?

Questions 37.

. #include<malloc.h>
      char *f()
      {char *s=malloc(8);
        strcpy(s,"goodbye");
     }

      main()
      {
      char *f();
      printf("%c",*f()='A');     }

 

Questions 39.
#define MAN(x,y) (x)>(y)?(x):(y)
      {int i=10;
      j=5;
      k=0;
      k=MAX(i++,++j);
      printf(%d %d %d %d,i,j,k);
      }
Ans. 10 5 0

Questions 40.
void main()
{
int i=7;
printf("%d",i++*i++);
}

Ans: 56

Previous Home Next