Troubleshoot Round 1 Set 3

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 Trouble Shoot
T
Trouble Shoot
Community Contributor
Quizzes Created: 1 | Total Attempts: 148
| Attempts: 148 | Questions: 20
Please wait...
Question 1 / 20
0 %
0/100
Score 0/100
1. What is the output of the following code? #include<stdio.h> main() {     int n,i;     n=f(6);     printf("%d",n); } f(int x) {     if(x==2)             return 2;     else     {         printf("+");         f(x-1);     } }  

Explanation

The code is using recursion to print a series of "+" symbols and then return the value 2. The function f(x) is called multiple times with decreasing values of x until x reaches 2. Each time the function is called, it prints a "+" symbol. Once x reaches 2, the function returns 2. Therefore, the output of the code will be a series of "+" symbols followed by the number 2.

Submit
Please wait...
About This Quiz
Troubleshoot Round 1 Set 3 - Quiz

This quiz titled 'TroubleShoot Round 1 Set 3' covers various topics in C programming, including function recursion, data types, and conditional logic.

2. Which is correct with respect to the size of the data types?

Explanation

The correct order of the size of the data types is char

Submit
3. What is function srand(unsigned)?

Explanation

The function srand(unsigned) is used to set the seed for the rand function in C++. The seed is a value that initializes the random number generator, allowing for the generation of different sequences of random numbers. By setting the seed using srand, we can ensure that the sequence of random numbers generated by rand is different each time the program is run.

Submit
4. Int main() {     char str[10]="Quest";     printf("%d,%d\n",strlen(str),sizeof(str));     return 0; }

Explanation

The code snippet declares a character array `str` with a size of 10 and initializes it with the string "Quest". The `strlen` function is used to determine the length of the string, which is 5 characters. The `sizeof` function is used to determine the size of the character array, which is 10 bytes. Therefore, the correct answer is 5,10.

Submit
5. #include <stdio.h>     int main()     {         int x = 2, y = 0;         int z = y && (y |= 10);         printf("%d\n", z);         return 0;     }

Explanation

The code snippet is using the logical AND operator (&&) to evaluate the expression "y && (y |= 10)". In this expression, the value of y is first evaluated, which is 0. Then, the second part of the expression is evaluated, which is "y |= 10". This expression is performing a bitwise OR operation between y and 10, and then assigning the result back to y. However, since the value of y is 0, the bitwise OR operation will not change the value of y. Finally, the overall expression evaluates to 0 because the logical AND operator requires both operands to be true, but since the value of y is 0, it is considered false. Therefore, the value of z is 0.

Submit
6. Int main() {     int x=5;     if(x>=10)       printf("Quest");     printf("CSE");     else  printf("2K19"); }

Explanation

The given code will result in a compilation error. This is because the ">" symbol is not properly encoded as ">" in the code. Therefore, the code will not be able to compile and will result in a compilation error.

Submit
7. #include<stdio.h> int main() {     int fun={     printf("C for Loop");     };     int x=5;     for(x=0;x<=fun;x++)     {        printf("%x",x);     }      }

Explanation

The code provided has a syntax error. The variable "fun" is declared as an integer but is assigned a block of code instead of a value. This is not valid in C programming. Therefore, a compile-time error will occur.

Submit
8. Main(int arg,char **argv) {    printf("Enter the character");    getchar();    sum(argv[1],argv[2]); } sum(num1,num2) int num1,num2; {     return num1+num2; }

Explanation

The given code will result in a compile error because the function sum() is not declared before it is used in the main() function. In C, functions need to be declared before they are used, either by including a function prototype at the beginning of the file or by defining the function before it is used. Since the sum() function is defined after it is used in the main() function, the compiler will not be able to recognize it and will throw a compile error.

Submit
9. Which one do you like?#include <stdio.h>     int main()     {         int i = 0;         int j = i++ + i;         printf("%d\n", j);     }

Explanation

The given code snippet initializes two variables, i and j, with i being assigned a value of 0. The expression i++ + i is then evaluated and assigned to j. The post-increment operator (i++) increments the value of i after it has been used in the expression, so j is assigned the value of 0 + 1, which is 1. Finally, the value of j is printed, resulting in the output of 1.

Submit
10. Int main(void) {     while(".") {     printf("Quest"); } return 0; }

Explanation

The given code is an infinite loop because the condition of the while loop is a non-null string literal ("."). Since the condition is always true, the loop will continue indefinitely. Inside the loop, the code prints "Quest" repeatedly. Therefore, the output will be "Quest" repeated infinitely.

Submit
11. #define FALSE -1 #define TRUE 1 #define NULL 0 main() {     if(NULL)          puts("NULL");     else if(FALSE)         puts("TRUE");     else         puts("FALSE"); }

Explanation

The code defines the values of FALSE, TRUE, and NULL as -1, 1, and 0 respectively. In the if statement, NULL is evaluated as false because it has a value of 0. Therefore, the code moves to the else if statement. Since FALSE is defined as -1, it evaluates to true and the code executes the statement "puts("TRUE")". Therefore, the output of the code will be "TRUE".

Submit
12. Void test(struct number n) {     n.x=100; } struct number{ int x; }; int main() {     struct number num;     test(num);     printf("%d\n",num.x);         return 0; }

Explanation

The code is attempting to pass a struct as an argument to a function, but the struct is not defined before the function prototype. This results in a compilation error because the compiler does not know the definition of the struct when it encounters the function call. Therefore, the correct answer is "Error".

Submit
13. In the absence of a exit condition in a recursive function, the following error is given __________

Explanation

In the absence of an exit condition in a recursive function, the function will keep calling itself indefinitely, leading to a stack overflow. This will result in a runtime error as the program will run out of memory to allocate for the function calls.

Submit
14. Int main() { int a; int b=5; a=0 && --b; printf("%d%d",a,b); }

Explanation

In this code, the variable 'a' is assigned the value of the logical AND operation between 0 and the pre-decremented value of 'b'. The logical AND operator returns 0 if any of the operands is 0. Since 'b' is initially 5, it is decremented to 4 but this does not affect the value of 'a' as 0 is already 0. Therefore, 'a' remains 0 and 'b' remains 5. The correct answer is 0 5.

Submit
15. #include <stdio.h>     int main()     {         reverse(1);     }     void reverse(int i)     {         if (i > 5)             exit(0);         printf("%d\n", i);         return reverse(i++);     }

Explanation

The given code will result in a stack overflow error. This is because the function reverse is being recursively called without any base case to stop the recursion. As a result, the function will continue to call itself indefinitely, causing the stack to overflow and resulting in a runtime error.

Submit
16. Void main() {     int a,b;     a=3,1;     b=(5,4);     printf("%d",a+b); }

Explanation

In the given code, there are two variables, 'a' and 'b', which are both integers.

In the line 'a=3,1;', there seems to be a typographical error. Instead of using a comma operator, it should be a semicolon. Therefore, the value of 'a' will be assigned as 3.

In the line 'b=(5,4);', there is a comma operator used. The comma operator evaluates both expressions and returns the value of the second expression. So, the value of 'b' will be assigned as 4.

Finally, the sum of 'a' and 'b' is printed, which is 7.

Submit
17. #include<stdio.h> #define x 5+2 int main( ) {      int i;      i=x*x*x;      printf("%d",i);      return 0; }

Explanation

The program defines a macro `x` as `5+2`. In the `main` function, the variable `i` is assigned the value of `x*x*x`, which is equivalent to `5+2*5+2*5+2`, which simplifies to `5+10+10+2`, resulting in `27`. The program then prints the value of `i`, which is `27`.

Submit
18. _______ occurs when a result is too large in magnitude to represent errors as a floating-point value of the required type.

Explanation

Underflow occurs when a result is too small in magnitude to be represented accurately as a floating-point value of the required type. In other words, it happens when a number is so close to zero that it cannot be precisely represented using the available number of bits. This can lead to loss of precision and inaccuracies in calculations.

Submit
19. Void Main() { int a=10; printf("%d", a); }

Explanation

This code will result in a runtime error because the printf function is being used without including the necessary header file. The printf function is part of the standard input/output library, which is declared in the header file "stdio.h". Without including this header file, the compiler will not recognize the printf function, leading to a runtime error.

Submit
20. Examination of the program step by step is called ______________

Explanation

Stepping refers to the process of examining a program step by step, allowing for a detailed analysis of its execution. It involves pausing the program at each step to observe the values of variables, the flow of control, and the effects of each instruction. This technique is commonly used in debugging to identify and fix errors in the code. By carefully stepping through the program, programmers can gain a better understanding of its behavior and pinpoint any issues that may be causing unexpected results.

Submit
View My Results

Quiz Review Timeline (Updated): Aug 16, 2024 +

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

  • Current Version
  • Aug 16, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 11, 2019
    Quiz Created by
    Trouble Shoot
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
What is the output of the following code? ...
Which is correct with respect to the size of the data types?
What is function srand(unsigned)?
Int main() ...
#include <stdio.h> ...
Int main() ...
#include<stdio.h> ...
Main(int arg,char **argv) ...
Which one do you like?#include <stdio.h> ...
Int main(void) ...
#define FALSE -1 ...
Void test(struct number n) ...
In the absence of a exit condition in a recursive function, the...
Int main() ...
#include <stdio.h> ...
Void main() ...
#include<stdio.h> ...
_______ occurs when a result is too large in magnitude to represent...
Void Main() { int a=10; printf("%d", a); }
Examination of the program step by step is called ______________
Alert!

Advertisement