Technical Interview Questions
Technical Interview Questions
#include<stdio.h>
int main()
{
char ch;
if(ch = printf(""))
printf("It matters\n");
else
printf("It doesn't matters\n");
return 0;
}
switch(i) becomes switch(1), then the case 1: block is get executed. Hence it
prints "Case1".
printf("This is c program."); is ignored by the compiler.
#include<stdio.h>
#include<math.h>
int main()
{
float n=1.54;
printf("%f, %f\n", ceil(n), floor(n));
return 0;
}
ceil(x) round up the given value. It finds the smallest integer not < x.
floor(x) round down the given value. It finds the smallest integer not > x.
printf("%f, %f\n", ceil(n), floor(n)); In this line ceil(1.54) round up the
1.54 to 2 and floor(1.54) round down the 1.54 to 1.
In the printf("%f, %f\n", ceil(n), floor(n)); statement, the format specifier
"%f %f" tells output to be float value. Hence it prints 2.000000 and 1.000000.
#include<stdio.h>
int i;
int fun();
int main()
{
while(i)
{
fun();
main();
}
printf("Hello\n");
return 0;
}
int fun()
{
printf("Hi");
}
#include<stdio.h>
int main()
{
int a=10;
void f();
a = f();
printf("%d\n", a);
return 0;
}
void f()
{
printf("Hi");
}
The function void f() is not visible to the compiler while going through main() function.
So we have to declare this prototype void f(); before to main() function. This kind of
error will not occur in modern compilers.
#include<stdio.h>
#define PRINT(int)
printf("int=%d, ", int);
int main()
{
int x=2, y=3, z=4;
PRINT(x);
PRINT(y);
PRINT(z);
return 0;
}
The macro PRINT(int) print("%d,", int); prints the given variable value in an
integer format.
Step 1: int x=2, y=3, z=4; The variable x, y, z are declared as an integer type
and initialized to 2, 3, 4 respectively.
Step 2: PRINT(x); becomes printf("int=%d,",x). Hence it prints 'int=2'.
Step 3: PRINT(y); becomes printf("int=%d,",y). Hence it prints 'int=3'.
Step 4: PRINT(z); becomes printf("int=%d,",z). Hence it prints 'int=4'.
#include<stdio.h>
#define JOIN(s1, s2)
printf("%s=%s %s=%s \n", #s1, s1, #s2, s2);
int main()
{
char *str1="India";
char *str2="BIX";
JOIN(str1, str2);
return 0;
}
str1=India str2=BIX
#include<stdio.h>
int main()
{
int x=30, *y, *z;
y=&x; /* Assume address of x is 500 and integer is 4 byte size
*/
z=y;
*y++=*z++;
x++;
printf("x=%d, y=%d, z=%d\n", x, y, z);
return 0;
}
#include<stdio.h>
int main()
{
char str[5] = "IndiaBIX";
return 0;
}
But, the modern compilers like Turbo C++ detects this as 'Error: Too many
initializers'.
#include<stdio.h>
int main()
{
static int arr[] = {0, 1, 2, 3, 4};
int *p[] = {arr, arr+1, arr+2, arr+3, arr+4};
int **ptr=p;
ptr++;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
*ptr++;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
*++ptr;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
++*ptr;
printf("%d, %d, %d\n", ptr-p, *ptr-arr, **ptr);
return 0;
}
1, 1, 1
2, 2, 2
3, 3, 3
3, 4, 4
Which of the following statements are correct about the program below?
#include<stdio.h>
int main()
{
char str[20], *s;
printf("Enter a string\n");
scanf("%s", str);
s=str;
while(*s != '\0')
{
if(*s >= 97 && *s <= 122)
*s = *s-32;
s++;
}
printf("%s",str);
return 0;
}
Output:
INDIABIX
#include<stdio.h>
#include<string.h>
void modify(struct emp*);
struct emp
{
char name[20];
int age;
};
int main()
{
struct emp e = {"Sanjay", 35};
modify(&e);
printf("%s %d", e.name, e.age);
return 0;
}
void modify(struct emp *p)
{
p ->age=p->age+2;
}
The struct emp is mentioned in the prototype of the function modify() before declaring
the structure.To solve this problem declare struct emp before the modify() prototype.
#include<stdio.h>
struct date
{
int day;
int month;
int year;
};
int main()
{
struct date d;
struct date *pdt;
pdt = &d;
return 0;
}
pdt.month = 12
&pdt.month = 12
d.month = 12
pdt->month = 12 ans
Point out the error in the following code?
typedef struct
{
int data;
NODEPTR link;
}*NODEPTR;
Error: in *NODEPTR
No error
None of above
#include<stdio.h>
int main()
{
const char *s = "";
char str[] = "Hello";
s = str;
while(*s)
printf("%c", *s++);
return 0;
}