Array C Programing

Answer: When the pointers are declared, they contain some garbage value that will be interpreted as memory addresses. They may not be valid addresses or they may point to some values that are wrong.

Since the compilers do not detect these errors, the programs with uninitialized pointers will produce wong results. It is therefore important and neccssary to initialize pointer variables carefully before they are used in the program.


Answer: The actual location of a variable in the memory is system dependent and therefore, the address of a variable is not known to us immediately. We can determine the address of a variable with the help of the operator (&) available in C.

The operator "&" immediately preceding a variable returns the address of the variable associated with it.



For example,

p = & sum;

would assign the address 22324 (the location of sum) to the variable p. The "&" operator is also known as address of operator.

The & operator can be used only with simple variables or an array element. The address of operator can not be used with constants, array names and expressions.

Following are the wrong use of pointers:

&125 (constant)

int x[10];

&x  (array names)

&(x-y)  (expression)