Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Compiled in Borland C++ compiler

The compiler doesn't mark it as any error.

  • I know that it's wrong,
  • but I want to know why it's showing the name of the company.

    1. And it doesn't show this message if I type any value less than 4,
    2. it gives different outputs for different such values, try some values like 50, 100,etc.

    Why it's showing such strange outputs.

Here is the program.

void main()
{

  int a=6;

  printf("%s",a);

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
630 views
Welcome To Ask or Share your Answers For Others

1 Answer

Your program behaviour is undefined since %s is not a valid format specifier for an int.

Exactly why it gives you the values it does is down to conjecture. The compiler also reserves the right to eat your cat. And your dog given that void main() is not compliant with later C standards.

C intentionally does not guard against your doing this as that would compromise the performance of the language. It's difficult (although not impossible as C is statically typed) for a compiler to warn you of this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...