LearnFrenzy
Sign in Take a free test

Declarations and Initializations · Find the Error · Question 8

Error: int* p, q; then q = &x Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

The program below has a bug. Which statement correctly describes it?

main.c
#include <stdio.h>

int main(void) {
    int x = 3, y = 4;
    int* p, q;
    p = &x;
    q = &y;
    printf("%d %d\n", *p, *q);
    return 0;
}
  • A x and y must be pointers
  • B Only p is a pointer; q is an int, so q = &y and *q are invalid Correct
  • C p must be initialised in its declaration
  • D There is no bug
Correct Answer: Option B

Each declarator needs its own *: int *p, *q; – or, clearer, one declaration per line.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links