'C' Interview Questions
* Without using (;)semicolon print the message?
Answer
Solution: 1
main()
{
if(printf(“Hello world”))
{
}
}
Solution: 2
main()
{
while(!printf(“Hello world”))
{
}
}
Solution: 3
main()
{
switch(printf(“Hello world”))
{
}
* Swap the two numbers without using third variable ?
}
Answer
#include<stdio.h>
int main()
{
int a=5,b=10;
//process one
a=b+a;
b=a-b;
a=a-b;
printf(“a= %d b= %d”,a,b);
//process two
a=5;
b=10;
a=a+b-(b=a);
printf(“na= %d b= %d”,a,b);
//process three
a=5;
b=10;
a=a^b;
b=a^b;
a=b^a;
printf(“na= %d b= %d”,a,b);
//process four
a=5;
b=10;
a=b-~a-1;
b=a+~b+1;
a=a+~b+1;
printf(“na= %d b= %d”,a,b);
//process five
a=5,
b=10;
a=b+a;
b=a-b;
a=a-b;
printf(“na= %d b= %d”,a,b);
getch();
}
* What is dangling pointer in c?
Answer
If any pointer is pointing the memory address of any variable but
after some variable has deleted from that memory location while
pointer is still pointing such memory location. Such pointer is known
as dangling pointer and this problem is known as dangling pointer problem.
0 comments:
Post a Comment