LearnFrenzy
Sign in Take a free test

C Variables · Find the Error · Question 6

Error: a variable name starting with a digit Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 6 Back to Exercise

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

main.c
#include <stdio.h>

int main(void) {
    int 2nd_place = 2;
    printf("%d\n", 2nd_place);
    return 0;
}
  • A Underscores are not allowed
  • B An identifier cannot begin with a digit; rename it, e.g. second_place Correct
  • C The value must be a string
  • D There is no bug
Correct Answer: Option B

The compiler reads 2nd_place as a malformed number. Identifiers must start with a letter or underscore.

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