C Programming Practice - Test 5

  • ISO/IEC 9899
Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Nchaudhuri31
N
Nchaudhuri31
Community Contributor
Quizzes Created: 19 | Total Attempts: 9,947
| Attempts: 122 | Questions: 20
Please wait...
Question 1 / 20
0 %
0/100
Score 0/100
1. What is the output of this program? void main() { int i=0,j=1,k; while(i

Explanation

The output of this program will be "Fibonacci nos". This is because the program is incomplete and the while loop condition is not provided. However, based on the given options "Prime nos", "Perfect nos", "Fibonacci nos", and "Armstrong no", it can be inferred that the program is likely checking for and printing Fibonacci numbers.

Submit
Please wait...
About This Quiz
C Programming Practice - Test 5 - Quiz

. Dear Learner,
This Assessment consists of questions to test your understanding on - C Programming
You may attempt the same and clarify doubts in WP Group. / With your Faculty Member
Regards,
Team SHIVAM

Personalize your quiz and earn a certificate with your name on it!
2. Void main() { static int i; while(i2)?i++:i--; printf(“%d”, i); }

Explanation

The given code snippet initializes the variable 'i' as a static variable. It then enters a while loop where it checks if 'i' is greater than 2. If it is, 'i' is incremented by 1, otherwise, it is decremented by 1. Since the initial value of 'i' is not specified, it can be assumed that it starts at the maximum value for a signed 16-bit integer, which is 32767. Therefore, the code will continue to increment 'i' until it reaches the maximum value, and then it will print the value of 'i', which is 32767.

Submit
3. What is the output of this program? void main() { int i=99; while(i

Explanation

not-available-via-ai

Submit
4. The following code stands for what? void main() { int m=60,n=25; if(m!=n) { while(m>n) m-=n; interchange(m,n); // assume the function interchange content of m & n } printf(“%d”,m); }

Explanation

The code is checking if m is not equal to n, and if so, it enters a while loop where it subtracts n from m until m becomes less than n. This process is similar to finding the greatest common divisor (GCD) of m and n. Therefore, the code is calculating the GCD of m and n and the correct answer is GCD(m,n).

Submit
5. What is the output of this program? #include #include void main() { printf(“%d”, (2*(1+rand()%4)); }

Explanation

The program generates a random number between 1 and 4 using the rand() function. It then multiplies this number by 2 and adds 1 to it. Since the range of the random number is limited to 1-4, the possible outputs of the expression are 3, 5, 7, and 9. All of these numbers are odd digits. Therefore, the correct answer is "any odd digit".

Submit
6. Pick the right alternative main() { int c=- -2; while(--c) printf("c=%d",c); }

Explanation

The code snippet initializes the variable c with the value - -2, which is equivalent to 2. The while loop decrements c by 1 each time it loops until c becomes 0. Since the initial value of c is 2, the loop will execute once and the value of c will become 1. Therefore, the output will be "c=1".

Submit
7. What is the output of this program? void main() { int i=122; while(i!=97) i--; while(i>65) i--; printf(“%c”,i); }

Explanation

The program starts with the variable i initialized to 122. It then enters a while loop that decrements i until it reaches 97. After that, it enters another while loop that continues to decrement i until it reaches 65. Finally, it prints the character corresponding to the ASCII value of i, which is 65. Therefore, the output of the program is A.

Submit
8. What is the output of this program? void main() { int i=0, j=1; while(i==!j) { printf(“%d %d”,!i,!j); i++; j++; } }

Explanation

The output of the program will be "1 0". This is because the while loop condition is checking if i is equal to the logical NOT of j. Initially, i is 0 and j is 1. The logical NOT of j is 0. Since i is not equal to 0, the condition is false and the loop does not execute. Therefore, the printf statement is not executed and there is no output.

Submit
9. Point out the error, if any in the for loop #include int main() { int i=1; for(;;) { printf("%d\n", i++); if(i>10) break; } return 0; }
10) break; } return 0; }">

Explanation

The given for loop does not have any errors. It is a valid infinite loop that will continue executing until the condition "i > 10" is met, at which point it will break out of the loop. The code will print the value of "i" and increment it by 1 in each iteration.

Submit
10. What will be the output? main() { char s[ ]="m"; int i; for(i=0;s[ i ];i++) printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]); }

Explanation

The given code defines a character array `s` with the value "m". It then declares an integer variable `i` and initializes it to 0.

The `for` loop iterates as long as `s[i]` is not a null character. In this case, since `s` only contains one character "m", the loop will execute once.

Inside the loop, the `printf` statement prints the characters `s[i]`, `*(s+i)`, `*(i+s)`, and `i[s]`.

In this case, all four characters will be "m" because `s[i]` is equivalent to `*(s+i)` is equivalent to `*(i+s)` is equivalent to `i[s]`, which all refer to the same memory location in the character array `s`.

Therefore, the output will be "mmmm".

Submit
11. What is the output of this program? void main() { int x=1; x=!x; while(x!=!x) { printf(“%d”,i); } }

Explanation

The program initializes the variable x to 1. It then uses the logical negation operator "!" to change the value of x to 0. In the while loop condition, it checks if x is not equal to the logical negation of x. Since the logical negation of x is 1, the condition becomes x != 1, which is false. Therefore, the while loop is not executed and nothing is printed. Hence, the output of the program is 0.

Submit
12. What is the output of this program? void main() { long int i=3; while(++i

Explanation

The output of this program is 3. This is because the variable i is initially set to 3. In the while loop, the expression (++i

Submit
13. Void main() { int a[5] = {1, 2, 3, 4, 5}; int i; for (i = 0; i < 5; i++) if ((char)a[i] == '5') printf("%d\n", a[i]); else printf("FAIL\n"); }

Explanation

The given code will print "FAIL" five times. This is because the code is using the "%d" format specifier in the printf function, which is used for printing integers. However, the elements of the array "a" are of type int, not char. When the code tries to compare the integer value with the character '5', it will not be equal and the "else" block will be executed, printing "FAIL" each time.

Submit
14. What main() { int i=0; while(+(+i--)!=0) i-=i++; printf("%d",i); }

Explanation

The code snippet starts with initializing the variable i to 0. Then, it enters a while loop where it checks if the value of +(+(i--)) is not equal to 0. The double negative sign before i-- is used to decrement the value of i by 1. However, the unary plus operator before the double negative sign does not have any effect on the value. Inside the loop, i is further decremented by 1 using i-=i++. Finally, the printf statement prints the value of i, which is -1.

Submit
15. Fill in the blank: #include #include void main() { int i,n; scanf(“%d”,&n); for(i=2;isqrt(n)) printf(“%d is ________”,n); }

Explanation

The given code is missing a condition in the for loop. It should be "i

Submit
16. #include void main() { double k = 0; for (k = 0.0; k < 3.0; k++); printf("%lf", k); }

Explanation

not-available-via-ai

Submit
17. What is the output of this program? void main() { int i, j; for(i=0,j=20; i!=j; i++,j--) { printf(“%c”,i+48); } }

Explanation

The program is using a for loop to iterate through the values of i and j. The loop will continue as long as i is not equal to j. Inside the loop, the program is printing the character representation of i+48. Since i starts at 0 and increments by 1 each iteration, the program will print the digits 0 to 9. Therefore, the output of the program will be the digits.

Submit
18. What is the output of this program? void main() { int k; for(k=10; k%2! =0 && k%3!=0;k--) if(k==1) break; printf(“%d”,k); }

Explanation

The program starts with initializing the variable k to 10. Then it enters a for loop where it checks two conditions: k%2 != 0 (k is not divisible by 2) and k%3 != 0 (k is not divisible by 3). If both conditions are true, it decrements the value of k by 1.

In this case, since 10 is divisible by 2, the condition k%2 != 0 is false, and the loop is not executed. Therefore, the value of k remains 10.

Finally, the program prints the value of k, which is 10.

Submit
19. What is the output of this program? void main() { int k; for(k=32768; k

Explanation

The output of this program is -32768. This is because the for loop starts with k=32768 and continues until k is less than -32768. However, since the initial value of k is already greater than the condition, the loop will not execute and the value of k will remain as -32768.

Submit
20. What is the output of this program? void main() { int i; for(i=10;--i%3==0;i--) printf(“%d”,i); }

Explanation

The program starts with the variable i initialized to 10. In the for loop condition, the expression --i%3==0 is evaluated. The --i decrements i by 1 and then checks if the result is divisible by 3. Since 10 is not divisible by 3, the condition is false and the loop exits. Therefore, the program only prints the value of i once, which is 9.

Submit
View My Results

Quiz Review Timeline (Updated): Feb 17, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Feb 17, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Jun 11, 2018
    Quiz Created by
    Nchaudhuri31
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is the output of this program?...
Void main() { static int i; while(i2)?i++:i--; printf(“%d”, i); }
What is the output of this program? void main() { int i=99; while(i
The following code stands for what?...
What is the output of this program?...
Pick the right alternative...
What is the output of this program? ...
What is the output of this program?...
10) break; } return 0; }" type="button" name="9" value="9" > 10) break; } return 0; }" > Point out the error, if any in the for loop...
What will be the output?...
What is the output of this program?...
What is the output of this program?...
Void main()...
What main() { int i=0; while(+(+i--)!=0) i-=i++; printf("%d",i); }
Fill in the blank:...
#include ...
What is the output of this program?...
What is the output of this program?...
What is the output of this program?...
What is the output of this program?...
Alert!

Advertisement