C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf

12. #include static num; int main(){ printf("%d",num); return 0; } int num =25;

i don't think the answer t this ques. is 25 coz variables are usable only from it's point of declaration.......here for answer to be 25 we have to use extern

12. #include extern int num; int main(){ printf("%d",num); return 0; } int num =25;

the answer given by the writer is correct, remember for the precedence of the operators, to help u,the first that yo must be operate is unary operators search what unary mean, then * / % then + - then shifting. now according to the given problem as substrahend has high precedence than shifting first evaluate the substraction and then shfting propert you will get the answer bye GEBREHIWET ABRHAM MEKELE INSTITUE OF TECHNOLGY MEKELE, ETHIOPIA

it seems that incorrect number 6 and 8; i have complied using gcc compier but they have value and are corect but the given answer does not much> how this is ??? bye gebrehiwet abrham mekele institue of technolgy ethiopia

to understand this problem, first you should know about the BITWISE SHIFT OPERATORS. there are two types of bitwise shift operators that is <<(left shift operator), >>(right shift operator). the shift operators are used to move bit patterns either to left or right. so here we have class=150 and private-public=5. that is 150 >> 5. now we have to convert 150 to bits. i.e. 0000 0000 1001 0110 >> 5. now shift(remove) rightmost 5 bits of operand(value) and add 5 zeros at left side. now it will 0000 0000 0000 0100. that is 4. similarly, for <<(left shift operator) shift leftmost 'n' bits and add 'n' zeros at right side. example : x=4 x << 2 => 0000 0000 0000 0100 << 2 now it will be 0000 0000 0001 0000 . x >> 2 => 0000 0000 0000 0100 >> 2 now it will be 0000 0000 0000 0001 .

to understand this problem, first you should know about the BITWISE SHIFT OPERATORS. there are two types of bitwise shift operators that is <<(left shift operator), >>(right shift operator). the shift operators are used to move bit patterns either to left or right. so here we have class=150 and private-public=5. that is 150 >> 5. now we have to convert 150 to bits. i.e. 0000 0000 1001 0110 >> 5. now shift(remove) rightmost 5 bits of operand(value) and add 5 zeros at left side. now it will 0000 0000 0000 0100. that is 4. similarly, for <<(left shift operator) shift leftmost 'n' bits and add 'n' zeros at right side. example : x=4 x << 2 => 0000 0000 0000 0100 << 2 now it will be 0000 0000 0001 0000 . x >> 2 => 0000 0000 0000 0100 >> 2 now it will be 0000 0000 0000 0001 .

less than(<) operator is a relational operator, it will return either 0 or 1. here y= _SMALL_ < 5 i.e. y = 11 < 5 ; , here 11<5 is falls so it will return 0, that is y=0. compiled on gcc compiler.

Q 7. Remember that digits are stored in two's complement. here 991+~91 in bits 91=>0101 1011,, ~91(one's compliment of 91)=>1010 0100. first bit is 1,so it will be negative, now look at -92 i.e. twos complement of 92 =>010 0100 ,,so we can say here ~91 is equals to -92.

91 =>0101 1011 ~91=>1010 0100 (first bit is 1,so it will be negative) ones complement of 0100100 =>1011011 + 1 =>1011100 i.e. 92. with sign bit it will be -92. now answer is 991-92=899. Ex : x=4 then ~x is -(x+1). that is -(4+1)=-5.

Q 17. to understand this problem first you should study clear about STRUCTURES concept..we can declare different data type as single using structure. and 'struct' is a key word to declare structures. ex : struct book { char author; int pages; float price; }; in problem no 17, b is a variable type of 'struct a' , and we can access structure members(int a) using .(dot) operator so b.a will be 10

output is incorrect in those questions because multiple definitions is not possible here static num=5 ; is a definition int num;// is also a definition extern int num; is a declaration

TELL ME WHAT PROBLEM IN THIS CODE...?(MILIND MEHKARKAR) #include int main() { int p,c,m; printf("Enter the marks of three subjects:"); scanf("%d %d %d",&p,&c,&m); if((p>=50 && c>=55 && m>=60)&&(p+c+m>=220||p+m>=130)) { printf("Admission is given"); } else { printf("Admission is not given"); } return 0; }

THIS PRG RIGHT OR NOT GIVE ME UR VALUABLE SUGGESTION...?'

#include #include void main() { int p,c,m,n,i; printf("Enter the marks of p,c,m"); scanf("%d %d %d",&p,&c,&m); if(p>=50) { if(c>=55) { if(m>=60) { if(p+c+m>=220) { n=p+c+m; printf("Admission is given %d",n); } else if(m+p>=130) { i=m+p; printf("Admission is given %d",i); } else { printf("Admission is not given"); } } else { printf("Admission is not given"); } } else { printf("Admission is not given"); } } else { printf("Admission is not given"); } getch(); }

A variable name in c can be composed of alphabets, digits, and underscore only. The first character of a variable name must be either an alphabet or underscore. Variable name is case sensitive. Home and home is recognised as two separate identifiers in c.

## 44 comments:

good tricky question bro!!1

good question !!!!!!!!!!!

awesome question ......good work

Very good work... but question 8 has wrong answer.

Answer of question 8 is correct. You may using different compiler. Check it in Turbo c 3.5 compiler.

Question 10 & 11 are giving error redefinition of ‘num’

with gcc compiler :-/

Nice questions........

gud que's like it

Can you pleaze explain question number 5.How does it give output 4?what is operator << doing?

nice questions .Good work

nice...

hiiiiii...this is SILKY BANKA ..i m nt getting ques no.7 and 8.

In question 5......

remember the value becomes half during every right shift(>>) and 150>>30-25

150>>5 times right shift

now ,150 becomes 75(1st time)

75 becomes 37(2nd time)

37 becomes 18(3rd time)

18 become 9 (4th time)

9 become 4 (5th time)

BY ABHINAV SAXENA

Tricky Questions dude...nice explanation

can't understand qs no. 7 and 17.... plz explain....

didnt get question 7. how 899 ? what is effect of +~ ?

question 7....

~ (xyz_123)= -92

991 + (-92)=899

12. #include

static num;

int main(){

printf("%d",num);

return 0;

}

int num =25;

i don't think the answer t this ques. is 25 coz variables are usable only from it's point of declaration.......here for answer to be 25 we have to use extern

12. #include

extern int num;

int main(){

printf("%d",num);

return 0;

}

int num =25;

Thank U very much for such interesting questions and answers.However, what is the difference b/n q.8 and q.9?

in question 5 class is a keyword how it is used as a variable name ?????????????

the answer given by the writer is correct, remember for the precedence of the operators, to help u,the first that yo must be operate is unary operators search what unary mean, then * / % then + - then shifting. now according to the given problem as substrahend has high precedence than shifting first evaluate the substraction and then shfting propert you will get the answer

bye GEBREHIWET ABRHAM

MEKELE INSTITUE OF TECHNOLGY

MEKELE, ETHIOPIA

it seems that incorrect number 6 and 8; i have complied using gcc compier but they have value and are corect but the given answer does not much> how this is ???

bye gebrehiwet abrham

mekele institue of technolgy

ethiopia

nice and good questions

10th ques's answer is wrong

can somebody please explain 8th question,how is the lessthan(<) operator working here and what will be the value of y?

#include

int main(){

register xyz_123=91;

auto pqr_123=991;

const _1a1_=pqr_123+~xyz_123;

printf("%d",_1a1_);

return 0;

In this question 7, the variable _1a1_ we have two underscores.. so it is an invalid declaration

CAN ANY ONE EXPLAIN ME Q.5 PLZZZZZZZZZZZZZZZZZZZZ XPLAIN ME IN DETAIL

very interesting..

to understand this problem, first you should know about the BITWISE SHIFT OPERATORS.

there are two types of bitwise shift operators that is <<(left shift operator), >>(right shift operator).

the shift operators are used to move bit patterns either to left or right.

so here we have class=150 and private-public=5.

that is 150 >> 5. now we have to convert 150 to bits. i.e. 0000 0000 1001 0110 >> 5. now shift(remove) rightmost 5 bits of operand(value) and add 5 zeros at left side. now it will 0000 0000 0000 0100. that is 4.

similarly, for <<(left shift operator) shift leftmost 'n' bits and add 'n' zeros at right side.

example : x=4

x << 2 => 0000 0000 0000 0100 << 2 now it will be 0000 0000 0001 0000 .

x >> 2 => 0000 0000 0000 0100 >> 2 now it will be 0000 0000 0000 0001 .

"class" is a keyword in c++ not in c language,, so we can use it as a variable name.

to understand this problem, first you should know about the BITWISE SHIFT OPERATORS.

there are two types of bitwise shift operators that is <<(left shift operator), >>(right shift operator).

the shift operators are used to move bit patterns either to left or right.

so here we have class=150 and private-public=5.

that is 150 >> 5. now we have to convert 150 to bits. i.e. 0000 0000 1001 0110 >> 5. now shift(remove) rightmost 5 bits of operand(value) and add 5 zeros at left side. now it will 0000 0000 0000 0100. that is 4.

similarly, for <<(left shift operator) shift leftmost 'n' bits and add 'n' zeros at right side.

example : x=4

x << 2 => 0000 0000 0000 0100 << 2 now it will be 0000 0000 0001 0000 .

x >> 2 => 0000 0000 0000 0100 >> 2 now it will be 0000 0000 0000 0001 .

less than(<) operator is a relational operator, it will return either 0 or 1.

here y= _SMALL_ < 5 i.e. y = 11 < 5 ; , here 11<5 is falls so it will return 0, that is y=0.

compiled on gcc compiler.

sorry,, it is (11<5) false not falls , spelling mistake.

Q 7.

Remember that digits are stored in two's complement.

here 991+~91

in bits 91=>0101 1011,, ~91(one's compliment of 91)=>1010 0100. first bit is 1,so it will be negative,

now look at -92 i.e. twos complement of 92 =>010 0100 ,,so we can say here ~91 is equals to -92.

91 =>0101 1011 ~91=>1010 0100 (first bit is 1,so it will be negative)

ones complement of 0100100 =>1011011 + 1 =>1011100 i.e. 92. with sign bit it will be -92.

now answer is 991-92=899.

Ex : x=4 then ~x is -(x+1). that is -(4+1)=-5.

Q 17. to understand this problem first you should study clear about STRUCTURES concept..we can declare different data type as single using structure. and 'struct' is a key word to declare structures.

ex : struct book

{

char author;

int pages;

float price;

};

in problem no 17, b is a variable type of 'struct a' , and we can access structure members(int a) using .(dot) operator

so b.a will be 10

output is incorrect in those questions because multiple definitions is not possible

here static num=5 ; is a definition

int num;// is also a definition

extern int num; is a declaration

good

class = class >> private - public; explation

TELL ME WHAT PROBLEM IN THIS CODE...?(MILIND MEHKARKAR)

#include

int main()

{

int p,c,m;

printf("Enter the marks of three subjects:");

scanf("%d %d %d",&p,&c,&m);

if((p>=50 && c>=55 && m>=60)&&(p+c+m>=220||p+m>=130))

{

printf("Admission is given");

}

else

{

printf("Admission is not given");

}

return 0;

}

THIS PRG RIGHT OR NOT GIVE ME UR VALUABLE SUGGESTION...?'

#include

#include

void main()

{

int p,c,m,n,i;

printf("Enter the marks of p,c,m");

scanf("%d %d %d",&p,&c,&m);

if(p>=50)

{

if(c>=55)

{

if(m>=60)

{

if(p+c+m>=220)

{

n=p+c+m;

printf("Admission is given %d",n);

}

else if(m+p>=130)

{

i=m+p;

printf("Admission is given %d",i);

}

else

{

printf("Admission is not given");

}

}

else

{

printf("Admission is not given");

}

}

else

{

printf("Admission is not given");

}

}

else

{

printf("Admission is not given");

}

getch();

}

thanks

que 8 ans will be 0

please clear that that question answer

int a=10;

printf("%d\n",~a);

printf("%d\n",!a);

what is answer this question explain its.

can a macro be used as a variable name

#include

#define ONE TWO

#define TWO ONE

main()

{

int TWO=1;

int ONE=2;

printf("%d %d", ONE, TWO);

}

A variable name in c can be composed of alphabets, digits, and underscore only.

The first character of a variable name must be either an alphabet or underscore.

Variable name is case sensitive. Home and home is recognised as two separate identifiers in c.

Post a Comment