Group B C Interview Question
Group B C Interview Question
1.Some question you have to check what will be the output, first understand the
program logic and find out the answer then compile the program using c
compiler and check whether your answer is correct are not, if it’s not correct
then any way during compilation you will get correct answer right then check
how the answer came what is the logic behind,
2. Some of the question you have to check online and understand (e.g.,
Questions no 14,22,23)
Question 1:
#include <stdio.h>
int main()
{
char *p = NULL;
char *q = 0;
if (p)
printf(" p ");
else
printf("nullp");
if (q)
printf("q\n");
else
printf(" nullq\n");
}
Question 2:
#include <stdio.h>
void solve() {
char ch[10] = "abcdefghij";
int ans = 0;
for(int i = 0; i < 10; i++) {
ans += (ch[i] - 'a');
}
printf("%d", ans);
}
int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 3:
#include <stdio.h>
struct School {
int age, rollNo;
};
void solve() {
struct School sc;
sc.age = 19;
sc.rollNo = 82;
printf("%d %d", sc.age, sc.rollNo);
}
int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 4:
#include <stdio.h>
void solve() {
int a[] = {1, 2, 3, 4, 5};
int sum = 0;
for(int i = 0; i < 5; i++) {
if(i % 2 == 0) {
sum += *(a + i);
}
else {
sum -= *(a + i);
}
}
printf("%d", sum);
}
int main() {
solve();
return 0;
}
Question 5:
#include <stdio.h>
void solve() {
int x = 2;
printf("%d", (x << 1) + (x >> 1));
}
int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 6:
#include <stdio.h>
#define CUBE(x) x * x * x
void solve() {
int ans = 216 / CUBE(3);
printf("%d", ans);
}
int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 7:
#include <stdio.h>
void solve() {
int n = 24;
int l = 0, r = 100, ans = n;
while(l <= r) {
int mid = (l + r) / 2;
if(mid * mid <= n) {
ans = mid;
l = mid + 1;
}
else {
r = mid - 1;
}
}
printf("%d", ans);
}
int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 8:
#include <stdio.h>
void solve() {
int x = 1, y = 2;
printf(x > y ? "Greater" : x == y ? "Equal" : "Lesser");
}
int main() {
solve();
return 0;
}int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 9:
#include <stdio.h>
void solve() {
int first = 10, second = 20;
int third = first + second;
{
int third = second - first;
printf("%d ", third);
}
printf("%d", third);
}
int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 10:
#include <stdio.h>
void solve() {
bool ok = false;
printf(ok ? "YES" : "NO");
}
int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 11:
#include <stdio.h>
void solve() {
int ch = 2;
switch(ch) {
case 1: printf("1 ");
case 2: printf("2 ");
case 3: printf("3 ");
default: printf("None");
}
}
int main() {
solve();
return 0;
}
-----------------------------------------------------------------------------------------------
Question 12:
#include <stdio.h>
#define VAL 3 * (2 + 6)
void solve() {
int a = 10 + VAL;
printf("%d", a);
}
int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 13:
#include <stdio.h>
void solve() {
int x = printf("Hello");
printf(" %d", x);
}
int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 14:
Explain dynamic memory allocation concept malloc, calloc, realloc, free.
------------------------------------------------------------------------------------------------
Question 15:
#include <stdio.h>
void solve() {
int x = printf("Hello");
printf(" %d", x);
}
int main() {
solve();
return 0;
}
------------------------------------------------------------------------------------------------
Question 16:
#include <stdio.h>
void reverse(int i);
int main()
{
reverse(1);
}
void reverse(int i)
{
if (i > 5)
return ;
printf("%d ", i);
return reverse((i++, i));
}
Question 17:
#include <stdio.h>
int x = 0;
int f()
{
if (x == 0)
return x + 1;
else
return x - 1;
}
int g()
{
return x++;
}
int main()
{
int i = (f() + g()) | g(); //bitwise or
int j = g() | (f() + g()); //bitwise or
}
-----------------------------------------------------------------------------------------
Question 18:
#include <stdio.h>
struct p
{
int x;
int y;
};
int main()
{
struct p p1[] = {1, 2, 3, 4, 5, 6};
struct p *ptr1 = p1;
printf("%d %d\n", ptr1->x, (ptr1 + 2)->x);
}
Question 19:
#include <stdio.h>
int main() {
int x[5] = {1, 2, 3, 4, 5};
int* ptr;
ptr = &x[2];
printf("*ptr = %d \n", *ptr);
printf("*(ptr+1) = %d \n", *(ptr+1));
printf("*(ptr-1) = %d", *(ptr-1));
return 0;
}
------------------------------------------------------------------------------------------------
Question 20:
#include <stdio.h>
int main()
{char flag=0x0f;
flag &= ~0x02;
printf("%d",flag);
return 0;
}
Question 21:
#include <stdio.h>
int main()
{int x = 10 ^ 2;
printf ("%d", x);
return 0;
}
------------------------------------------------------------------------------------------------
Question 22:
Explain void pointer, NULL pointer, dangling pointer and wild pointer
------------------------------------------------------------------------------------------------
Question 23:
Write the program to swap two variables value without third number using
pointer
-----------------------------------------------------------------------------------------------
Question 24:
1. #include <stdio.h>
2. struct student
3. {
4. char *name;
5. };
6. struct student s;
7. struct student fun(void)
8. {
9. s.name = "newton";
10. printf("%s\n", s.name);
11. s.name = "alan";
12. return s;
13. }
14. void main()
15. {
16. struct student m = fun();
17. printf("%s\n", m.name);
18. m.name = "turing";
19. printf("%s\n", s.name);
20. }
------------------------------------------------------------------------------------------------
Question 25:
1. #include <stdio.h>
2. struct student
3. {
4. char *name;
5. };
6. void main()
7. {
8. struct student s, m;
9. s.name = "st";
10. m = s;
11. printf("%s%s", s.name, m.name);
12. }
------------------------------------------------------------------------------------------------
Question 26:
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. int main()
8. {
9. struct point p = {1};
10. struct point p1 = {1};
11. if(p == p1)
12. printf("equal\n");
13. else
14. printf("not equal\n");
15. }
------------------------------------------------------------------------------------------------
Question 27:
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. struct notpoint
8. {
9. int x;
10. int y;
11. };
12. struct point foo();
13. int main()
14. {
15. struct point p = {1};
16. struct notpoint p1 = {2, 3};
17. p1 = foo();
18. printf("%d\n", p1.x);
19. }
20. struct point foo()
21. {
22. struct point temp = {1, 2};
23. return temp;
24. }
------------------------------------------------------------------------------------------------
Question 28:
1. #include <stdio.h>
2. struct point
3. {
4. int x;
5. int y;
6. };
7. struct notpoint
8. {
9. int x;
10. int y;
11. };
12. int main()
13. {
14. struct point p = {1};
15. struct notpoint p1 = p;
16. printf("%d\n", p1.x);
17. }
------------------------------------------------------------------------------------------------
Question 29:
1. #include <stdio.h>
2. struct student
3. {
4. char *name;
5. };
6. struct student s[2];
7. void main()
8. {
9. s[0].name = "alan";
10. s[1] = s[0];
11. printf("%s%s", s[0].name, s[1].name);
12. s[1].name = "turing";
13. printf("%s%s", s[0].name, s[1].name);
14. }
------------------------------------------------------------------------------------------------
Question 30:
1. #include <stdio.h>
2. void first()
3. {
4. printf("first");
5. }
6. void second()
7. {
8. first();
9. }
10. void third()
11. {
12. second();
13. }
14. void main()
15. {
16. void (*ptr)();
17. ptr = third;
18. ptr();
19. }
------------------------------------------------------------------------------------------------