Quick Google Search

Undefined in C


If the “grammar” was not defined for a  given particular operation, it is called as
“Undefined”. So each compiler would give different answers for a  given particular operation.
Usually compilers won’t check such ‘Undefined’ usage. So it is our responsibility to check it.

6.1 Example
char buffer[5];
strcpy(buffer, "Hello World"); /* Undefined */

  For example the operation of copying a string to buffer, which is smaller than the string is
‘Undefined’. That means Dennis Ritchie didn’t say (or define) anything about such operations.

6.2 Frequently Asked Undefined Questions
a) What is the output of following code?

int i = 7;
printf( “%d”,  i++ * i++ );

b) What would happen to the array after executing the following statements?

int a[5], i = 1;
a[i] =  i++;

c) What is the value of i after the execution of the following statement?

int i = 7;
i = ++i;

 These  idiotic questions are very often asked in Indian Programming world. The outputs
are undefined. Even if such questions are asked, the right answer will be “the result is undefined”.

Note
For the above program, you may get some output. But it is wrong. You have to understand that compilers
may not check ‘Undefined’ grammars.

No comments:

Popular Posts