The C code ‘for(;;)’ represents an infinite loop. It can be terminated by ___________
break
exit(0)
abort()
terminate
What will be the correct syntax for running two variable for loop simultaneously?
for (i = 0; i < n; i++) for (j = 0; j < n; j += 5)
for (i = 0, j = 0; i < n, j < n; i++, j += 5)
for (i = 0; i < n;i++){} for (j = 0; j < n;j += 5){}
none of the mentioned
Which for loop has range of similar indexes of ‘i’ used in for (i = 0;i < n; i++)?
for (i = n; i>0; i–)
for (i = n; i >= 0; i–)
for (i = n-1; i>0; i–)
for (i = n-1; i>-1; i–)
Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3)?
variable
function
typedef
macros
What will be the output of the following C code?
#include int main() { short i; for (i = 1; i >= 0; i++) printf("%d\n", i);
}
The control won’t fall into the for loop
Numbers will be displayed until the signed limit of short and throw a runtime error
Numbers will be displayed until the signed limit of short and program will successfully terminate
This program will get into an infinite loop and keep printing numbers with no errors
What will be the output of the following C code?
#include void main() { int k = 0; for (k) printf("Hello"); }
Compile time error
hello
Nothing
Varies
What will be the output of the following C code?
#include void main() { int k = 0; for (k < 3; k++) printf("Hello"); }
Compile time error
Hello is printed thrice
Nothing
Varies
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"); }
Run time error
Hello is printed thrice
Hello is printed twice
Hello is printed infinitely
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("%lf", k); }
2.000000
4.000000
3.000000
Run time error
What will be the output of the following C code?
#include void main() { int k; for (k = -3; k < -5; k++) printf("Hello"); }
Hello
Infinite hello
Run time error
Nothing
What will be the output of the following C code?
#include int main() { int i = 0; for (; ; ;) printf("In for loop\n"); printf("After loop\n"); }
Compile time error
Infinite loop
After loop
Undefined behaviour
What will be the output of the following C code? #include int main() { int i = 0; for (i++; i == 1; i = 2) printf("In for loop "); printf("After loop\n"); }
In for loop after loop
After loop
Compile time error
Undefined behaviour
What will be the output of the following C code?
#include int main() { int i = 0; for (foo(); i == 1; i = 2) printf("In for loop\n"); printf("After loop\n"); } int foo() { return 1; }
After loop
In for loop after loop
Compile time error
Infinite loop
What will be the output of the following C code?
#include int main() { int *p = NULL; for (foo(); p; p = 0) printf("In for loop\n"); printf("After loop\n"); }
In for loop after loop
Compile time error
Infinite loop
Depends on the value of NULL
What will be the output of the following C code?
#include int main() { for (int i = 0;i < 1; i++) printf("In for loop\n"); }
Compile time error
In for loop
Depends on the standard compiler implements
Depends on the compiler
What will be the output of the following C code? #include int main() { while () printf("In while loop "); printf("After loop\n"); }
In while loop after loop
After loop
Compile time error
Infinite loop
What will be the output of the following C code?
#include int main() { do printf("In while loop "); while (0); printf("After loop\n"); }
In while loop
In while loop after loop
After loop
Infinite loop
What will be the output of the following C code?
#include int main() { int i = 0; do { i++; printf("In while loop\n"); } while (i < 3); }
In while loop In while loop In while loop
In while loop In while loop
Depends on the compiler
Compile time error
How many times i value is checked in the following C code?
#include int main() { int i = 0; do { i++; printf("in while loop\n"); } while (i < 3); }
2
3
4
1
How many times i value is checked in the following C code?
#include int main() { int i = 0; while (i < 3) i++; printf("In while loop\n"); }
2
3
4
1
What will be the output of the following C code?
#include void main() { int i = 2; do { printf("Hi"); } while (i < 2) }
Compile time error
Hi Hi
Hi
Varies
What will be the output of the following C code? #include void main() { int i = 0; while (++i) { printf("H"); } }
H
H is printed infinite times
Compile time error
Varies
What will be the output of the following C code?
#include void main() { int i = 0; do { printf("Hello"); } while (i != 0); }
Nothing
H is printed infinite times
Hello
Run time error
What will be the output of the following C code? #include void main() { char *str = ""; do { printf("hello"); } while (str); }
Nothing
Run time error
Varies
Hello is printed infinite times
What will be the output of the following C code?
#include void main() { int i = 0; while (i < 10) { i++; printf("hi\n"); while (i < 8) { i++; printf("hello\n"); } } }
Hi is printed 8 times, hello 7 times and then hi 2 times
Hi is printed 10 times, hello 7 times
Hi is printed once, hello 7 times
Hi is printed once, hello 7 times and then hi 2 times
What is an example of iteration in C?
for
while
do-while
all of the mentioned
How many times while loop condition is tested in the following C code snippets, if i is initialized to 0 in both the cases?
while (i < n) i++; ————- do i++; while (i <= n);
n, n
n, n+1
n+1, n
n+1, n+1
What will be the output of the following C code?
#include int main() { int i = 0; while (i = 0) printf("True\n"); printf("False\n"); }
True (infinite time)
True (1 time) False
False
Compiler dependent
What will be the output of the following C code?
#include int main() { int i = 0, j = 0; while (i < 5, j < 10) { i++; j++; } printf("%d, %d\n", i, j); }
5, 5
5, 10
10, 10
Syntax error
Which loop is most suitable to first perform the operation and then test the condition?
for loop
while loop
do-while loop
none of the mentioned
Which keyword can be used for coming out of recursion?
break
return
exit
both break and return
What will be the output of the following C code?
#include int main() { int a = 0, i = 0, b; for (i = 0;i < 5; i++) { a++; continue; } }
2
3
4
5
What will be the output of the following C code? #include int main() { int a = 0, i = 0, b; for (i = 0;i < 5; i++) { a++; if (i == 3) break; } }
1
2
3
4
The keyword ‘break’ cannot be simply used within _________
do-while
if-else
for
while
Which keyword is used to come out of a loop only for that iteration?