Home > Blockchain >  When we take input in a string why size does not matter?
When we take input in a string why size does not matter?

Time:03-29

#include<stdio.h>`

int main() {
  char b[1];
  scanf("%s",b);
  puts(b);
  // gets(b);
  // puts(b);
  // gets(b);
  // puts(b);
  return 0;
}

output:

hello_world
hello_world

I expect that it should give max limit error but it didn't gave that. Why?

CodePudding user response:

"give max limit error" --> C does not specify a "max limit error" required.

C is like riding a bicycle without training wheels. If code is not well directed, it fails.

Use a larger buffer and a width limit like:

char b[100];
scanf("           
  • Related