Recent questions tagged c-programming

9 9 votes
4 4 answers
320
320 views
Given the following two files, what will happen when they are compiled and linked together?file1.cstatic int count = 3; void update() { count = count + 1; }main.c#include...
5 5 votes
3 3 answers
218
218 views
What will happen when the following code is compiled and linked?#include <stdio.h int main() { extern int a; printf("%d", a); return 0; }$\texttt{0}$ Garbage value Compil...
6 6 votes
2 2 answers
203
203 views
What is the output of the following code?#include <stdio.h int main() { extern int i; printf("%d", i); return 0; } int i = 100;Garbage value $\texttt{0}$ $\texttt{100}$ C...
5 5 votes
1 1 answer
179
179 views
In which stage is the following code#include <stdio.h>is replaced by the contents of the file $\texttt{stdio.h}$?During editing During linking During execution During pre...
5 5 votes
1 1 answer
195
195 views
Is there any difference between the following declarations?extern int fun(); int fun();Both are identical No difference, except $\texttt{extern int fun();}$ is probably i...
6 6 votes
3 3 answers
252
252 views
What is the output of the following code?#include <stdio.h int main() { register int x = 10; int *p = &x; printf("%d", *p); return 0; }$\texttt{10}$ $\texttt{0}$ Garbage ...
8 8 votes
2 2 answers
223
223 views
What can be said about the output of the following code?#include <stdio.h int main() { auto int x; printf("%d", x); return 0; }Output is always $\texttt{0}$ Output is alw...
8 8 votes
2 2 answers
216
216 views
What is the output of the following code?#include <stdio.h int a; static int b; int main() { printf("%d %d", a, b); return 0; }$\texttt{0\ 0}$ Garbage values $\texttt{1\ ...
7 7 votes
2 2 answers
245
245 views
What is the output of the following code?#include <stdio.h void fun() { static int x = 1; x = x + 2; printf("%d ", x); } int main() { fun(); fun(); fun(); return 0; }$\te...
7 7 votes
2 2 answers
215
215 views
What is the output of the following code?#include <stdio.h int x = 10; int main() { int x = 20; printf("%d", x); return 0; }
6 6 votes
2 2 answers
261
261 views
What is the output of the following code?#include <stdio.h struct Point { int x; int y; }; int main() { struct Point p = {4, 7}; p.x = p.x + 3; p.y = p.x + p.y; printf("%...
5 5 votes
2 2 answers
229
229 views
What is the output of the following code?#include <stdio.h struct Student { int roll; int marks; }; int main() { struct Student s1; s1.roll = 10; s1.marks = 85; printf("%...
11 11 votes
2 2 answers
232
232 views
What is the output of the following code?#include <stdio.h #define SQUARE(x) x * x int main() { int a = 3; int result = SQUARE(a + 1); printf("%d", result); return 0; }$\...
8 8 votes
3 3 answers
239
239 views
What is the output of the following code?#include <stdio.h int fun(int n) { if (n <= 1) return n; return fun(n - 1) + fun(n - 3); } int main() { printf("%d", fun(5)); ret...
7 7 votes
3 3 answers
228
228 views
What is the output of the following code?#include <stdio.h void update(int *p, int *q) { *p = *p + 2; *q = *q + 3; *p = *p + *q; } int main() { int a = 5; update(&a, &a);...
8 8 votes
2 2 answers
292
292 views
What is the output of the following code?#include <stdio.h int main() { int i, j, sum = 0; for (i = 1; i <= 4; i++) { for (j = 1; j <= 5; j++) { if (j % i == 0) continue;...
7 7 votes
1 1 answer
229
229 views
What is the output of the following code?#include <stdio.h int solve(int n) { static int x = 1; if (n == 0) return x; x = x + n; return solve(n - 1); } int main() { print...
6 6 votes
1 1 answer
222
222 views
What is the output of the following code?#include <stdio.h struct Student { int marks; }; void update(struct Student s) { s.marks = s.marks + 10; } int main() { struct St...
7 7 votes
1 1 answer
192
192 views
What is the output of the following code?#include <stdio.h int fun(int n) { if (n == 0) return 1; return n * fun(n - 2); } int main() { printf("%d", fun(6)); return 0; }
7 7 votes
1 1 answer
215
215 views
What is the output of the following code?#include <stdio.h int main() { int a = 5, b = 10; int *p = &a; int q = &p; q = q + 3; p = &b; q = q + a; printf("%d %d", a, ...
7 7 votes
1 1 answer
202
202 views
What is the output of the following code?#include <stdio.h void change(int *p, int *q) { *p = *p + 4; *q = *p + *q; p = q; *p = *p - 3; } int main() { int a = 6, b = 10; ...
8 8 votes
1 1 answer
191
191 views
What is the output of the following code?#include <stdio.h int main() { int i, j, count = 0; for (i = 1; i <= 4; i++) { for (j = 1; j <= 4; j++) { if (i * j 6) break; co...
7 7 votes
1 1 answer
178
178 views
What is the output of the following code?#include <stdio.h int calc(int n) { if (n == 1) return 2; return n + calc(n - 1); } int main() { printf("%d", calc(4)); return 0;...
7 7 votes
1 1 answer
201
201 views
What is the output of the following code?#include <stdio.h void fun() { static int x = 3; int y = 2; x = x + y; y = y + x; printf("%d ", x); } int main() { fun(); fun(); ...
7 7 votes
1 1 answer
207
207 views
What is the output of the following code?#include <stdio.h int main() { int a = 8, b = 12; int *p = &a; int *q = &b; *p = *p + *q; q = p; *q = *q - 5; printf("%d %d", a, ...
9 9 votes
2 2 answers
357
357 views
What is the output of the following code?#include <stdio.h int main() { int a = 10, b = 20; int *p, *q; p = &a; q = &b; *p = *p + 5; *q = *p + *q; p = q; *p = *p - 10; pr...
8 8 votes
3 3 answers
321
321 views
What is the output of the following code?#include <stdio.h int main() { int x = 3, y = 1; switch (x - 1) { case 1: y = y + 2; case 2: y = y * 3; case 3: y = y - 1; break;...
5 5 votes
2 2 answers
244
244 views
What is the output of the following code?#include <stdio.h int main() { int i, j, count = 0; for (i = 1; i <= 4; i++) { for (j = 1; j <= 4; j++) { if (i == j) continue; i...
3 3 votes
2 2 answers
261
261 views
What is the output of the following code?#include <stdio.h int update(int x) { x = x + 3; return x * 2; } int main() { int a = 4, b; b = update(a); printf("%d %d", a, b);...
5 5 votes
2 2 answers
289
289 views
What is the output of the following code?#include <stdio.h int main() { int a[5] = {2, 4, 1, 3, 5}; int i, sum = 0; for (i = 0; i < 5; i++) { if (a[i] % 2 == 0) sum = sum...