0% found this document useful (0 votes)
8 views2 pages

Debugging Event Questions

The document contains debugging questions for C programming, divided into two parts: finding errors in code snippets and guessing the output of certain expressions. Each question includes a code example and a description of the error or output. The errors range from incorrect assignments to array bounds issues and pointer mismanagement.

Uploaded by

yraj17999
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Debugging Event Questions

The document contains debugging questions for C programming, divided into two parts: finding errors in code snippets and guessing the output of certain expressions. Each question includes a code example and a description of the error or output. The errors range from incorrect assignments to array bounds issues and pointer mismanagement.

Uploaded by

yraj17999
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Debugging Event Questions for C Programming

Part 1: Find the Error (20 Questions)

Question 1
#include <stdio.h>
int main() {
int x = 5;
int y = 0;
if (x = y) {
printf("x and y are equal\n");
} else {
printf("x and y are not equal\n");
}
return 0;
}

**Error:** Error: Assignment (`=`) instead of comparison (`==`) in the `if` condition.

Question 2
#include <stdio.h>
int main() {
int arr[3] = {1, 2, 3};
printf("%d", arr[3]);
return 0;
}

**Error:** Error: Array index out of bounds (`arr[3]` is invalid).

Question 3
#include <stdio.h>
int main() {
int a = 10;
int *ptr;
*ptr = &a;
printf("%d", *ptr);
return 0;
}

**Error:** Error: Incorrect pointer assignment (`*ptr = &a` should be `ptr = &a`).

Question 4
#include <stdio.h>
int main() {
char str[5] = "Hello";
printf("%s", str);
return 0;
}

**Error:** Error: String `"Hello"` requires 6 bytes (including `\0`), but `str` is only size 5.

Question 5
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", num);
printf("You entered: %d", num);
return 0;
}

**Error:** Error: Missing `&` in `scanf` (`scanf("%d", &num)`).

Part 2: Guess the Output (10 Questions)

Question 21
#include <stdio.h>
int main() {
int x = 5;
printf("%d", x++ + ++x);
return 0;
}

**Output:** Output: Undefined behavior (sequence point violation).

Question 22
#include <stdio.h>
int main() {
int a = 1, b = 2, c = 3;
printf("%d", a + (b = c));
return 0;
}

**Output:** Output: `4` (`b = c` makes `b = 3`, then `a + b = 4`).

You might also like