Hello Friends today i am posting about technical question of C .in this i would like to write top 30 question which is asked by interviewer to the students.
1.Write a c program to print Hello world without using any semicolon?
Answer:
Solution: 1
void main(){
if(printf("Hello world")){
}
}
Solution: 2
void main(){
while(!printf("Hello world")){
}
}
Solution: 3
void main(){
switch(printf("Hello world")){
}
}
2.Swap two variables without using third variable?
#include<stdio.h>
int main(){
int a=5,b=10;
//1
a=b+a;
b=a-b;
a=a-b;
printf("a= %d b= %d",a,b);
//2
a=5;
b=10;
a=a+b-(b=a);
printf("\na= %d b= %d",a,b);
//3
a=5;
b=10;
a=a^b;
b=a^b;
a=b^a;
printf("\na= %d b= %d",a,b);
//4
a=5;
b=10;
a=b-~a-1;
b=a+~b+1;
a=a+~b+1;
printf("\na= %d b= %d",a,b);
//5
a=5,
b=10;
a=b+a,b=a-b,a=a-b;
printf("\na= %d b= %d",a,b);
return 0;
}
3.What is wild pointer in c?
A pointer in c which has not been initialized is known as wild pointer.
Example:
What will be output of following c program?
int main(){
int *ptr;
printf("%u\n",ptr);
printf("%d",*ptr);
return 0;
}
Output: Any address
Garbage value
Here ptr is wild pointer because it has not been initialized. There is difference between the NULL pointer and wild pointer. Null pointer points the base address of segment while wild pointer doesn’t point any specific memory location.
4.What are merits and demerits of array in c?
Merits:
(a) We can easily access each element of array.
(b) Not necessity to declare too many variables.
(c) Array elements are stored in continuous memory location.
Demerit:
(a) Wastage of memory space. We cannot change size of array at the run time.
(b) It can store only similar type of data.
0 comments:
Post a Comment
Enter Here Your Ideas and Comment to improve this Blog