Take FREE!! Online Mettl Mock Test to Crack TechM and Other Companies Written Exams.
Get Off-Campus Placement Jobs Info !!!
TCS NQT Technical and Managerial Round Interview Questions

C Interview Questions and Answers

21 / 123

What is the difference between 'for' and 'while' loops?

For loop is used when we know how many times

22 / 123

Which bitwise operator is suitable for checking whether a particular bit is ON or OFF?

to check if the ith bit is on or off in a number n following  bitwise operation is used.

flag = n&(1<<i) ;

if the value of flag is zero then the bit is set otherwise not.
explanation of above approach is as follows.

1. lets assume n is 9 so its bitwise operator is 1001 and bitwise representation of 1 is 0001

2.to check if 4th bit is on we do left shift by 4 on 1 (1<<4) which shift the bits in one to left by 4 unit now the (1<<4)=1000

3.Finally bitwise and operation is performed so  1001&1000 = 1000 which is not zero so it means that 4th bit of  9 is set

23 / 123

Which bitwise operator is suitable for turning OFF a particular bit in a number?

The bitwise operator xor i.e '^' is used to turn off a particular number

by performing the following operations say we want to turn the ith bit off in a number n

then n = n^(1<<i)

24 / 123

What is equivalent of multiplying an unsigned int by 2: left shift of number by 1 or right shift of number by 1?

multiplying a number by two is equivalent to bitwise left shift of a number by 1 for eg

1 has a binary representation as 00001 left shift by 1 will make it 00010 which is 2.

right shift is equivalent to divide a number by 2 .

left shift is equivalent to multiply a number by 2.

25 / 123

What is an Enumeration Constant?

Enumarations are list of integer constants, by default value is zero.

26 / 123

What is a structure?

Structure is a function which contains different types of data types and allocation different memory location.

27 / 123

What are the differences between a structure and a union?

Structure- It is an user defined data function that allow to store multiple type of data in a single unit.

It occupies sum of memory of all location.

Whereas, Union- It is also an user defined data function that allow to store multiple type of data in a single unit.

But it occupies memory of largest member only.

28 / 123

What are the advantages of unions?

1.memory.

2.easy to declare.

29 / 123

How can typedef be to define a type of structure?

No Discussion on this question yet!

30 / 123

Write a program that returns 3 numbers from a function using a structure.

#include<stdio.h>

struct name{

int a;

int b;

int c;

};

struct name func(){

struct name s1 ;

s1.a=1;

s1.b=2;

s1.c=3;

return s1;

}

int main(){

struct name val = func();

}