C Questions March 18, 2023 | No Comments 0 votes, 0 avg 732 123456789101112131415 C Questions 1 / 15 1. What will be the output of the following C code? #include #include int main() { char line[3]; FILE *fp; fp = fopen("newfile.txt", "r"); while (fgets(line, 3, fp)) fputs(line, stdout); return 0; } A. Compilation error B. Infinite loop C. Segmentation fault D. No.of lines present in file newfile 2 / 15 2. What will be the output of the following C code? #include int main() { int a = 1, b = 2, c = 3; int *ptr1 = &a, *ptr2 = &b, *ptr3 = &c; int **sptr = &ptr1; //-Ref *sptr = ptr2; } A. ptr1 points to a B. ptr1 points to b C. sptr points to ptr2 D. none of the mentioned 3 / 15 3. What will be the output of the following code snippet? #include void solve() { int a = 3; int res = a++ + ++a + a++ + ++a; printf("%d", res); } int main() { solve(); return 0; } A. 12 B. 24 C. 20 D. 18 4 / 15 4. What will be the output of the following C code? #include void foo(int *ary[]); int main() { int ary[2][3]; foo(ary); } void foo(int *ary[]) { int i = 10, j = 2, k; ary[0] = &i; ary[1] = &j; *ary[0] = 2; for (k = 0;k < 2; k++) printf("%dn", *ary[k]); } A. 2 2 B. Compile time error C. Undefined behaviour D. 10 2 5 / 15 5. Which of the following is the correct syntax to declare a 3 dimensional array using pointers? A. char *a[][]; B. char **a[]; C. char ***a; D. all of the mentioned 6 / 15 6. What will happen if a header file is included in a program twice? A. Program will throw an error B. Program will throw an exception C. Program will run normally D. None of these 7 / 15 7. Which of the following is a correct format for declaration of function? A. return-type function-name(argument type); B. return-type function-name(argument type){} C. return-type (argument type)function-name; D. all of the mentioned 8 / 15 8. Which of the following is not a valid C variable name? A. int number; B. float rate; C. int variable_count; D. int $main; 9 / 15 9. What is output of below code? int main() { char name[]="Cppbuz"; int len; int size; len = strlen(name); size = size_of(name); printf("%d,%d",len,size); return 0; } A. 6,6 B. 6,7 C. 7,7 D. o,o 10 / 15 10. Multiple values of the same variable can be tested using ___. A. switch B. for C. function D. All of these 11 / 15 11. What will be the output of the following C code? #include int main(){ int i, j; for (i = 2; i < 10; i++) { for (j = 2; j <= (i / j); j++) if (!(i % j)) break; if (j > (i / j)) printf("%d ", i); } return 0; } A. 2 3 4 5 6 7 8 9 B. 3 5 7 9 C. 2 3 5 7 D. 2 3 5 7 11 12 / 15 12. What will be the output of the following C code? #include void main() { double k = 0; for (k = 0.0; k < 3.0; k++) printf("Hello"); } A. Run time error B. Hello is printed thrice C. Hello is printed twice D. Hello is printed infinitely 13 / 15 13. The standard header _______ is used for variable list arguments (…) in C. A. stdio.h B. stdlib.h C. math.h D. stdarg.h 14 / 15 14. Which of the following option is the correct representation of the following C statement? e = a * b + c / d * f; A. e = (a * (b +(c /(d * f)))); B. e = ((a * b) + (c / (d * f))); C. e = ((a * b) + ((c / d)* f)); D. Both e = ((a * b) + (c / (d * f))); and e = ((a * b) + ((c / d)* f)); 15 / 15 15. What will be the output of this program? int main() { int a=10, b=20; printf("a=%d b=%d",a,b); a=a+b; b=a-b; a=a-b; printf("a=%d b=%d",a,b); return 0; } A. a = 20, b = 20 B. a=10, b=20 C. a=20, b=10 D. a=10, b=10 Your score isThe average score is 38% LinkedIn Facebook VKontakte 0% Restart quiz By WordPress Quiz plugin Written by Shubhranshu Shekhar, who has trained 20000+ students in coding. Kritika Papne Questions, Quiz