Quiz - 2 Codegeeks

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 Vivek Rajpoot
V
Vivek Rajpoot
Community Contributor
Quizzes Created: 1 | Total Attempts: 108
| Attempts: 108 | Questions: 16
Please wait...
Question 1 / 16
0 %
0/100
Score 0/100
1. In which line there is an error in the program : 1 int main() 2 { 3    char ch[10]; 4   scanf("%s", ch); 5    printf("%s", ch); 6    return 0; 7 }

Explanation

The error in the program is in line 4. The format specifier used in the scanf function is "%s" which is used for reading a string. However, the variable "ch" is declared as a character array with a size of 10, which means it can only store a string of maximum length 9 (including the null character). This can lead to a buffer overflow if the user enters a string longer than 9 characters. To fix this error, the size of the character array should be increased or a limit should be imposed on the input string length.

Submit
Please wait...
About This Quiz
Quiz - 2 Codegeeks - Quiz

Quiz - 2 CODEGEEKS assesses understanding of C programming output questions, focusing on printf function behavior and basic C syntax. It's designed for learners to test their knowledge... see morein practical coding scenarios. see less

2. What is output  #include<stdio.h> int main() {       int a = 500, b, c;       if(a>=400)            b = 300;       c = 200;       printf("%d %d", b, c); }

Explanation

The correct answer is 300 200. In this code, the variable "a" is assigned a value of 500. The if statement checks if "a" is greater than or equal to 400, which is true. Therefore, the value of "b" is assigned 300. The value of "c" is assigned 200. Finally, the printf statement prints the values of "b" and "c", which are 300 and 200 respectively.

Submit
3. What is the value of the num: int num = -17 % 4;

Explanation

The value of the variable "num" is -1. The expression "-17 % 4" calculates the remainder when -17 is divided by 4. Since -17 divided by 4 is -4 with a remainder of -1, the value of "num" is -1.

Submit
4. What is the output of the following program? int num = 10; while ( num < 12 ) {     cout << num;     num++; }

Explanation

The program starts with the variable "num" initialized to 10. The while loop condition checks if "num" is less than 12. Since 10 is less than 12, the loop is executed. Inside the loop, the value of "num" is printed, which is 10. Then, "num" is incremented by 1. The loop continues until "num" reaches 12. Therefore, the output of the program is "1011".

Submit
5. What is the output: int num = 10; while( num < 10 ) {      cout << num;      num++; }

Explanation

The condition in the while loop is "num

Submit
6. What is the output: #include< stdio.h > int main() {      int n =9;      ( (n == 9.5) ? printf(" Correct \n ") : printf(" wrong \n") );       return 0; }

Explanation

The output of the code is "wrong". This is because the expression (n == 9.5) evaluates to false since n is an integer and 9.5 is a floating-point number. Therefore, the second part of the ternary operator is executed, which is to print "wrong".

Submit
7. What is the output: printf(" %d " , printf("%dhii", printf("hello")));

Explanation

The output is "hello5hii4" because the printf function is being nested within itself. The innermost printf statement "printf("hello")" prints "hello" and returns the number of characters printed, which is 5. Then, the next printf statement "printf("%dhii", 5)" prints "5hii" and returns the number of characters printed, which is 4. Finally, the outermost printf statement "printf(" %d ", 4)" prints the value of 4 and returns the number of characters printed, which is also 4. Therefore, the overall output is "hello5hii4".

Submit
8. What is the value of num? int num = 4/3*2.4;

Explanation

The value of num is 2 because the expression 4/3*2.4 is evaluated from left to right according to the order of operations. First, 4 divided by 3 equals 1.3333. Then, 1.3333 multiplied by 2.4 equals 3.2. However, since the variable num is declared as an int, the decimal portion is truncated, resulting in the value 3. Therefore, the correct answer is 2.

Submit
9. What is the value of the num: int num = 17 % -4;

Explanation

The expression "17 % -4" calculates the remainder when 17 is divided by -4. In this case, the result is 1 because when 17 is divided by -4, the quotient is -4 and the remainder is 1. Therefore, the value of the variable "num" is 1.

Submit
10. IN which line there is an error  1 #include <stdio.h> 2 int main() 3 { 4     int x = 10, y = 15;      (x + 1) = 15; 5     if( x%2 == y%3) 6             printf("Carpathians\n"); 7     8 }

Explanation

not-available-via-ai

Submit
11. what will be the output of the following program? #include int main() {        int i = 4, j = -1, k = 0, w,  x, y, z;        w = i || j || k;        x = i && j && k;        y = i || j && k;         z = i && j || k;        printf(" w = %d x = %d y = %d z = %d \n" , w, x, y,z);       return 0; }

Explanation

The program is using logical operators to assign values to variables w, x, y, and z. The logical OR operator (||) returns true (1) if at least one of the operands is true. In the case of w = i || j || k, since i is true (non-zero), the expression evaluates to true and w is assigned the value 1. The logical AND operator (&&) returns true (1) only if all of the operands are true. In the case of x = i && j && k, since j is false (0), the expression evaluates to false and x is assigned the value 0. The expression y = i || j && k is evaluated from left to right. Since i is true (non-zero), the expression i || j evaluates to true. Then, the expression true && k evaluates to the value of k. Since k is false (0), the expression evaluates to false and y is assigned the value 0. The expression z = i && j || k is evaluated from left to right. Since i is true (non-zero), the expression i && j evaluates to the value of j. Since j is false (0), the expression evaluates to false. Then, the expression false || k evaluates to the value of k. Since k is true (non-zero), the expression evaluates to true and z is assigned the value 1.

Submit
12. What is output: printf( "%d", printf('' %d" , printf("hii"));

Explanation

The code snippet uses nested printf statements. The innermost printf("hii") statement prints "hii" and returns the number of characters printed, which is 3. The next printf statement ("%d", 3) prints the value 3. Finally, the outermost printf statement ("%d", 3) prints the value 3 as well. So the overall output is "hii31".

Submit
13. What is output of following program: #include< stdio.h> int main() {      int i = 65;      char j = 'A';      if( i == j )            printf("C is WOW \n");      else              printf(" C is headache \n");        return 0;    }

Explanation

The program compares the integer value of variable i (65) with the ASCII value of character j ('A'), which is also 65. Since the condition i == j is true, the program executes the code inside the if statement and prints "C is WOW" as the output.

Submit
14. What is output: printf("%d" printf("hello") );

Explanation

The printf function is used to print the output. In this code, the inner printf function "printf("hello")" will print "hello" on the console. The outer printf function will then print the number of characters printed by the inner printf function, which is 5. Therefore, the output will be "hello5".

Submit
15. What is the output : int num = 10; while(num < 12 ); {      cout << num ;      num++; }

Explanation

The while loop condition is not properly defined. The semicolon after the while statement creates an empty loop body, which means the loop will keep executing indefinitely without any code to execute. As a result, nothing will be printed on the console.

Submit
16. What is output: int a = 10, b = 20, c = 30; printf("%d %d %d");

Explanation

The correct answer is "30 20 10". The printf function is used to print the values of variables a, b, and c. The format specifier "%d" is used to print the values as integers. Since the variables are printed in the order a, b, c, the output will be 30 20 10.

Submit
View My Results

Quiz Review Timeline (Updated): Jul 12, 2024 +

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

  • Current Version
  • Jul 12, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Oct 04, 2018
    Quiz Created by
    Vivek Rajpoot
Cancel
  • All
    All (16)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
In which line there is an error in the program :...
What is output  ...
What is the value of the num: int num = -17 % 4;
What is the output of the following program? ...
What is the output: ...
What is the output: ...
What is the output: ...
What is the value of num? int num = 4/3*2.4;
What is the value of the num: int num = 17 % -4;
IN which line there is an error  ...
What will be the output of the following program? ...
What is output: ...
What is output of following program: ...
What is output: printf("%d" printf("hello") );
What is the output : ...
What is output: ...
Alert!

Advertisement