void main()
{
 static int a[]={ 0,1,2,3,4}; // if here static removed that hence error why?
	int *p[]={ a,a+1,a+2,a+3,a+4};
	int **ptr=p;
	clrscr();
	printf(" base address is %u",a);
	ptr++;
	
getch();
 }

in above code in "staic int a[] " line integer array define as static why it need?

Recommended Answers

All 5 Replies

Please post the error and specify which compiler you're using. Also, are you compiling as C or C++?

I did not get an error using vc++ 2008 express, compiled for both C and C++ and was ok. So if you have an error then either it is your compiler or you didn't post something.

Please post the error and specify which compiler you're using. Also, are you compiling as C or C++?

In C code and for Turbo C/C++ compiler

if static removed than error producing "Illegal Initialization"..
if next line of this line (pointer array) omitted then no need to static but if take a pointer array of that int array.. then necessary to define static int a[] ..

>I did not get an error using vc++ 2008 express, compiled for both C and C++ and was ok.
Visual Studio gives a warning when compiled as C because it supports this as an extension. Assuming the OP is compiling as C89, the error when removing static is legit because C89 requires aggregate initializers to be constant expressions. C99 and C++ don't have that restriction, IIRC.

Strange -- if I change options to "Compile as C code" then I get a several errors on line 4 of the original post. But no errors or warnings are produced if I change back to the default "Compile as C++ code", even though the filename has *.c extension. And I have the warning level set to 4 in both cases.

error C2093: 'p' : cannot be initialized using address of automatic variable

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.