Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Write a MIN macro program that takes two arguments and returns the smallest of both arguments.

Answer»

#DEFINE MIN(NUM1,NUM2) ( (NUM1) <= (NUM2) ? (NUM1) : (NUM2) )

USEFUL Resource

C Interview Questions

C++ Interview Questions

Practice Coding

InterviewBit Blog

Online C++ Compiler

2.

Write a program to print numbers from 1 to 100 without making use of conditional operators?

Answer» VOID MAIN (){ INT i=0; while (100 – i++) PRINTF ("%d", i);}
3.

Write a program to check if a number is a power of 2 or not.

Answer»

We can do this by using BITWISE operators.

void main (){ int num; printf ("Enter any no:"); scanf ("%d", &num); if (num & & ((num & num-1) == 0)) printf ("NUMBER is a POWER of 2"); else printf ("Number is not a power of 2");}
4.

How will you swap two variables? Write different approaches for the same.

Answer» int NUM1=20, NUM2=30, temp;temp = num1;num1 = num2;num2 = temp;
  • Using Arithmetic Operators:
int num1=20, num2=30;num1=num1 + num2;num2=num1 - num2;num1=num1 - num2;
  • Using Bit-Wise Operators:
int num1=20, num2=30;num1=num1 ^ num2;num2=num2 ^ num1;num1=num1 ^ num2;
  • Using One-liner Bit-wise Operators:
int num1=20, num2=30;num1^=num2^=num1^=num2;

The order of evaluation here is right to left.

  • Using One-liner Arithmetic Operators:
int num1=20, num2=30;num1 = (num1+num2)-(num2=num1);

Here the order of evaluation is from left to right.

5.

Write an Embedded C program to multiply any number by 9 in the fastest manner.

Answer»

This can be achieved by involving bit manipulation techniques - Shift left OPERATOR as shown below:

#INCLUDE<stdio.h>VOID main(){ int num; PRINTF(“Enter NUMBER: ”); scanf(“%d”,&num); printf(“%d”, (num<<3)+num);}