Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between variable and data object in C language?

I was reading C Primer Plus and came across the following lines that I couldn't understand-

Pointers? What are they? Basically, a pointer is a variable (or, more generally, a data object)whose value is a memory address.

Just for reference,I came across these lines earlier-

Consider an assignment statement. Its purpose is to store a value at a memory location. Data object is a general term for a region of data storage that can be used to hold values. The C standard uses just the term object for this concept. One way to identify an object is by using the name of a variable.

I tried googleing but couldn't find anything.These basic terminologies are confusing me so please help me understand these terms.

like image 437
aj14 Avatar asked Dec 24 '22 23:12

aj14


1 Answers

A data object is a memory location that stores information used by the program.

A variable is a name used in the program to refer to a data object.

So if you write:

int a;

it tells the compiler to create a data object that can hold an integer, and in the program you can use the name a to access that data object.

A pointer is a data object whose value is the location in memory of some other data object. So if you do:

int *pa = &a;

you're creating a variable pa that refers to a data object whose contents are the address of the data object created as a result of the a variable declaration.

like image 173
Barmar Avatar answered Jan 19 '23 00:01

Barmar