"PRadyut" <pradyutb@gmail.com> writes:[color=blue]
> In my borland compiler 5.5.1 it shows 0 if the global variable is
> undefined
>
> For example the code below
> /*-----new.c---------*/
> #include <stdio.h>
>
> int global;
>
>
> int *pointer = &global;
>
> int getData(void);
> int main(void)
> {
> int test = NULL;
>
> printf("%d, %d, %d", getData(), global, test);
> return 0;
> }
>
> int getData(void)
> {
> return *pointer;
> }
>
> /*---EOF-------------*/
> the o/p is 0, 0, 0
> It shows(outputs) null if command line arguments are empty but not in
> this case
>
> Please can somebody please clarify[/color]
Please don't top-post. Your response goes below, or interspersed
with, any quoted material, which should be reduced to what's actually
necessary. The idea is to allow each article to be read from top to
bottom. See most of the other articles in this newsgroup for example.
The declaration
int test = NULL;
is questionable. NULL is (a macro that expands to) a null pointer
context; it should only be used as a pointer value. (If NULL happens
to be defined as 0, it can also be used as an integer value.) Also,
you should end your output with a newline; change the "%d, %d, %d"
to "%d, %d, %d\n".
Apart from that, your program seems to behave as it should. The
getData() function returns the value of the variable to which it
points, which happens to be "global"; since global variables are
implicitly initialized to zero, that's the value that's printed.
Printing the value of "global" directly gives you the same result.
And the variable "test" also has the value 0, even though you chose an
odd (and non-portable) way to initialize it.
I don't understand what you're saying about command line arguments.
The program doesn't look at its command line arguments, and in my own
testing it isn't affected by them.
Please clarify what you're asking.
--
Keith Thompson (The_Other_Keith)
kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.