Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C pointers Question

Tags:

c

pointers

For :

int *a;

a is an address where an integer can be stored. &a is an address where a is stored. Then, where is &a stored? And, where is &(&a) stored? And, where is &(&(&a)) stored? Where does this storing of addresses stop?

like image 705
simplfuzz Avatar asked Jul 10 '09 14:07

simplfuzz


People also ask

What is pointers in C with example?

A pointer is a variable that stores the address of another variable. Unlike other variables that hold values of a certain type, pointer holds the address of a variable. For example, an integer variable holds (or you can say stores) an integer value, however an integer pointer holds the address of a integer variable.

What is pointer in C in interview questions?

Answer: A pointer is similar to a variable but the difference is that pointers store the address of a location in memory and the variable stores the value. In other words, we can say, a pointer is used to reference a location in the memory.

Is pointers in C tough?

Pointers are arguably the most difficult feature of C to understand. But, they are one of the features which make C an excellent language. In this article, we will go from the very basics of pointers to their usage with arrays, functions, and structure.

What is pointer in C Short answer?

A pointer is a variable that stores the memory address of another variable as its value. A pointer variable points to a data type (like int ) of the same type, and is created with the * operator.


2 Answers

If you don't explicitly write &a it will not be stored anywhere. If you do write then the address will be computed and stored either in an unnamed variable (temporary) or a named varible you write.

For example:

functionCall( &a ); // address will be in a temporary variable used for passing the parameter
int** b = &a; // address will be stored in variable b
otherFunctionCall( &&a ); // illegal, since &a is an expression operator & can't be applied to it
like image 130
sharptooth Avatar answered Sep 21 '22 20:09

sharptooth


&a is a constant.

&(&a) is illegal.

like image 38
J-16 SDiZ Avatar answered Sep 23 '22 20:09

J-16 SDiZ