C Programming Tricky Questions and Answers PDF for Interview

C Programming Tricky Questions and answers for freshers, beginners & people who are preparing for the interview or conducting the interview.  Go through the below questions & do let me know if you want to ask or share any of your programming interview questions which can help other people.

c programming tricky questions

 

C Programming Tricky Interview Questions

How can you print any text within double quotes ” “ in c programming language?

Answer:

#include<iostream>

int main()

{

std::cout << “\”interviewquestions.guru\””;

}

How you can print any text without using ; (semicolon) in c?

Answer:

#include <iostream>

int main()

{

if (std::cout << “tricky interview questions on c “)

{

}

// Or you can use below code instead of if use switch

switch (printf(“tricky questions on c “))

{

}

}

What is the use of a ‘\0’ character?

It is referred to as a terminating null character and is used primarily to show the end of a string value.

What is the difference between the = (equals) & == (double equals) symbol?

Answer: Double Equals is to compare & single equal is for assigning a value.

What is the output of the below program?

#define int char

main()

{

int i=77;

printf(“print sizeof(i)=%d”,sizeof(i));

}

Answer: print sizeof(i)=1(Since the #define replaces the string int by the macro char)

What will be the output if we call main in main?

main()  {  main();  }

Answer: you will get an Runtime error : Stack overflow

Choose the correct answer what would be output of below code.

#include <stdio.h>

int main()

{

float   a = 0.0;

float   b = 0.0;

int      c = 0;

a = (b/c) * 1000;

printf(“a = %f\n” );

}

  1. Will a be 0?
  2. Garbage value?
  3. Value like 0.000000?

Answer: C

How many times it will print interview question on c.

int main()

{

int x;

for(x=-1; x<=10; x++)

{

if(x < 5)

continue;

else

break;

printf(“Interview Question on c”);

}

return 0;

}

  1. Infinite Time
  2. 11 Times
  3. 0 Time
  4. 10 Times

Answer: C

Where in C program should we use keyword “Break”?

Answer: Break is used to control out of the block of code which is executing, we can use in loop statements or switch statements.

What are the modifiers available in C?

Answer: There are five modifiers in c.

  1. Short
  2. Long
  3. Signed
  4. Unsigned
  5. Long Long

What is main function in C?

Answer: The main function in c is the one which executes which you run the program but it is not the first function to be executed as there is another start() function which gets executed to compile the libraries.

Write a program in c to print all unique elements in an array.

Answer:

#include <stdio.h>
#define MAX_SIZE 100

int main()
{
int array[MAX_SIZE], frequency[MAX_SIZE];
int size, i, j, count;

printf(“Please enter size of the array: “);
scanf(“%d”, &size);
printf(“Please enter elements you want in array: “);
for(i=0; i<size; i++)
{
scanf(“%d”, &array[i]);
frequency[i] = -1;
}

/* This loop is to find the frequency of each element */
for(i=0; i<size; i++)
{
count = 1;
for(j=i+1; j<size; j++)
{
if(array[i] == array[j])
{
count++;
frequency[j] = 0;
}
}

if(frequency[i] != 0)
{
frequency[i] = count;
}
}

printf(“\nAll Unique elements in the array are: “);
for(i=0; i<size; i++)
{
if(frequency[i] == 1)
{
printf(“%d “, array[i]);
}
}

return 0;
}

 

C Programming other Questions

Commonly asked C Questions

PDF

 

Leave a Comment

error: Content is protected !!