Trouble Shoot Round-1 Set-1

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
T
Trouble
Community Contributor
Quizzes Created: 1 | Total Attempts: 182
| Attempts: 182 | Questions: 20
Please wait...
Question 1 / 20
0 %
0/100
Score 0/100
1. Int main() {     int c=2;     switch(c)     {         case 0: printf("CSE");         case 1: printf("Quest");         case 2: printf("Trouble");         case 3: printf("Shoot");         default: printf("2k19");     }     return 0; }

Explanation

The correct answer is "TroubleShoot2k19" because the switch statement is evaluating the value of the variable c. Since c is equal to 2, it matches the case 2 and prints "Trouble". However, there are no break statements after each case, so the execution continues to the next cases. As a result, it also prints "Shoot" and "2k19". Therefore, the final output is "TroubleShoot2k19".

Submit
Please wait...
About This Quiz
Trouble Shoot Round-1 Set-1 - Quiz

TROUBLE SHOOT Round-1 Set-1 is a programming quiz focused on C language. It assesses understanding of switch statements, loops, conditionals, and character manipulation. This quiz is ideal for... see morelearners aiming to enhance their programming skills in C. see less

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

Explanation

The given code will not produce a compilation error. The output will be "2K19". The if statement checks if the value of x is greater than or equal to 10, which is false in this case. Therefore, the code inside the if statement will not be executed. The code outside the if statement will be executed, which is the printf("2K19") statement, resulting in the output "2K19".

Submit
3. How many times "Trouble Shoot" will print? int main()  {   int x;   for(x=-1; x<=10; x++)   {     if(x < 5)       continue;     else       break;     printf("Trouble Shoot");   }    return 0; }

Explanation

The loop will run 6 times because x starts at -1 and increments by 1 each time until it reaches 5. However, when x is 5, the condition in the if statement is not satisfied, so the loop is exited and "Trouble Shoot" is not printed at all. Therefore, the correct answer is 0 times.

Submit
4. 3. int main() {   char arr[5]="Quest";   printf("%s", arr);   return 0;  }

Explanation

The code declares an array of characters called "arr" with a size of 5. The string "Quest" is assigned to the array. The printf function is then used to print the string stored in "arr". Therefore, the output of the code will be "Quest".

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

Explanation

The given code will result in an error because the condition inside the while loop is not specified. The while loop requires a condition to be evaluated, and since there is no condition provided (the dot symbol is not a valid condition), it will result in a syntax error.

Submit
6. Int main() {   int a = 100, b = 74;   if (a++ > 100 && b++ > 200)     printf("High values with a = %d b = %dn", a, b);   if (a++ < 100 || b++ < 200)     printf("Low values with a = %d b = %dn", a, b);  }

Explanation

The correct answer is "Low values with a = 102 b = 75" because the if statement `(a++

Submit
7. Void PrintCount() {  static int Count=1;  printf("%d ",Count);  Count=Count+1; } int  main() {  PrintCount();  PrintCount();  PrintCount();  return 0; }

Explanation

The function PrintCount is called three times in the main function. The variable Count is declared as a static variable inside the PrintCount function, which means it retains its value between function calls.

Initially, Count is set to 1. The first time PrintCount is called, it prints the value of Count (which is 1) and then increments it by 1. So the first output is 1.

The second time PrintCount is called, it prints the value of Count (which is now 2) and then increments it by 1. So the second output is 2.

The third time PrintCount is called, it prints the value of Count (which is now 3) and then increments it by 1. So the third output is 3.

Therefore, the correct answer is "1 2 3".

Submit
8. 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 giving an error because the function `test` is trying to modify the value of `num.x`, but it is passed by value to the function. This means that the function is working with a copy of `num`, and any changes made to `n.x` inside the function will not affect the original `num.x`. To fix this error, the function `test` should take a pointer to `struct number` as a parameter, allowing it to modify the original `num.x`.

Submit
9. #include<stdio.h> #include<stdlib.h> int main() {     unsigned char;     FILE *fp;     fp=fopen("trial", "r");     if(!fp)     {         printf("Unable to open file");         exit(1);     }     fclose(fp);     return 0; }

Explanation

The given code does not contain any syntax errors or logical errors. The code opens a file named "trial" in read mode using the fopen() function. If the file does not exist or cannot be opened, the code prints "Unable to open file" and exits the program. Otherwise, the code closes the file using the fclose() function and returns 0. Therefore, there is no error in the code.

Submit
10. Int main() {     int x[10]={0,1,2,3,4,5,6,7,8,9};     int *ptr1,*ptr2;     ptr1=&x[0];     ptr2=&x[5];          printf("%p\n",(ptr1+ptr2));          return 0; }

Explanation

The expression `(ptr1+ptr2)` is not valid because it is trying to add two pointers together. Pointer arithmetic can only be performed when adding or subtracting an integer value to a pointer. In this case, `ptr1` and `ptr2` are both pointers to integers, so adding them together is not allowed. Therefore, the code will not compile and a compilation error will occur.

Submit
11. Int main() {   int x = 0, y = 0;   if(x > 0)     if(y > 0)       printf("True");    else     printf("False");  }

Explanation

The correct answer is "No Output" because the condition `x > 0` is not satisfied, so the inner `if` statement is not executed. Therefore, there is no output printed.

Submit
12. Int main() {  int x,y,z;  x = '1'-'0'; /* line-1 */  y = 'a'-'b'; /* line-2 */  z = x + y;  printf("%d",z);  } 

Explanation

The correct answer is 0 because the expression '1'-'0' in line-1 will result in the integer value 1-0=1. Similarly, the expression 'a'-'b' in line-2 will result in the integer value 97-98=-1. Therefore, the value of x is 1 and the value of y is -1. When x and y are added together in line-3, the result is 1+(-1)=0. Finally, the value of z is printed, which is 0.

Submit
13. #include<stdio.h> int main() {        int i;        for(i=0;i<=3;i++);         printf("%d",i);         return 0; }

Explanation

The correct answer is 4.

In this code, there is a for loop that runs from i=0 to i
After the loop, the printf statement is executed, which prints the value of i, which is 4 because the loop did not change the value of i. Therefore, the output of the code is 4.

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

Explanation

The code snippet declares a character pointer variable `str` and assigns it the address of the string "Quest". The `strlen()` function is then used to calculate the length of the string, which is 5. The `sizeof()` function is used to determine the size of the pointer variable `str`, which is 8 bytes on most systems. Therefore, the output of the `printf()` function will be "5,8".

Submit
15. Void main() { int a,b,c; a+b=c; } What type of error we get

Explanation

The given code has a semantic error. In the line "a+b=c;", the assignment operator (=) is used incorrectly. The left side of the assignment operator should be a variable, but in this case, it is an expression (a+b). This violates the syntax rules of the programming language and results in a semantic error.

Submit
16. 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 result of the logical AND operation between 0 and the pre-decremented value of "b". Since the value of "b" is initially 5, it is decremented to 4 before the logical AND operation is performed. The logical AND operator returns 0 if any of the operands is 0, otherwise it returns 1. In this case, the result of the logical AND operation is 0 because one of the operands is 0. Therefore, "a" is assigned the value 0. The value of "b" remains 5 because the decrement operation is not assigned to it. Finally, the printf statement prints the values of "a" and "b", which are 0 and 5 respectively.

Submit
17. #include<stdio.h> int main() {     char ch;     int i;     scanf("%c", &i);     scanf("%d", &ch);     printf("%c %d", ch, i);     return 0; }

Explanation

The correct answer is "Error: we may not get input for second scanf() statement". This is because the format specifier used in the first scanf() statement is incorrect. The variable 'i' is an integer, but the format specifier used is '%c' which is for characters. This will cause an error and the input for 'i' will not be read correctly. As a result, the second scanf() statement may not receive any input, leading to an error.

Submit
18. #include<stdio.h>    #include<stdlib.h>      int main()    {        char *ptr;        free(ptr);        return 0           }

Explanation

The program is attempting to free a pointer variable without allocating any memory to it. This results in undefined behavior and can lead to a segmentation fault or an aborted program with a core dump. In this case, the program is likely to be aborted and a core dump is generated.

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

Explanation

The given code is written in C language. It initializes a variable 'a' with the value 10 and then prints the value of 'a' using the printf function. Since the code does not have any syntax errors, it will compile successfully. However, it will result in a runtime error because the format specifier used in the printf function is incorrect. The correct format specifier for an integer is "%d" but in the code, it is written as "%quot;%d%quot;". This will cause the code to throw 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 the programmer to analyze the execution flow and identify any errors or bugs. It involves executing the program line by line, pausing at each step to observe the variables, data values, and program state. This method helps in understanding the program's behavior and identifying the exact point where an error occurs. By stepping through the code, programmers can effectively debug and troubleshoot their programs.

Submit
View My Results

Quiz Review Timeline (Updated): Mar 5, 2023 +

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

  • Current Version
  • Mar 05, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Feb 26, 2019
    Quiz Created by
    Trouble
Cancel
  • All
    All (20)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
Int main()...
Int main() ...
How many times "Trouble Shoot" will print?...
3. ...
Int main(void) ...
Int main() { ...
Void PrintCount() ...
Void test(struct number n) ...
#include<stdio.h> ...
Int main() ...
Int main() { ...
Int main() { ...
#include<stdio.h> ...
Int main() ...
Void main() { int a,b,c; a+b=c; } What type of error we get
Int main() ...
#include<stdio.h> ...
#include<stdio.h> ...
Void Main() { int a=10; printf("%d", a); }
Examination of the program step by step is called ______________
Alert!

Advertisement