Difference between variable and data object in C language? -


i reading c primer plus , came across following lines couldn't understand-

pointers? they? basically, pointer variable (or, more generally, data object)whose value memory address.

just reference,i came across these lines earlier-

consider assignment statement. purpose store value @ memory location. data object general term region of data storage can used hold values. c standard uses term object concept. 1 way identify object using name of variable.

i tried googleing couldn't find anything.these basic terminologies confusing me please me understand these terms.

in c, object takes storage. c 2011 online draft:

3. terms, definitions, , symbols
...
3.15
1 object
region of data storage in execution environment, contents of can represent values

an lvalue expression designates object such contents of object may read or modified (basically, expression can target of assignment lvalue). while c standard doesn't define term variable, can think of identifier designates object:

int var; 

the identifier var designates object stores integer value; expression var lvalue, since can read and/or modify object through it:

var = 10; printf( "%d\n", var ); 

a pointer expression value location of object. pointer variable object stores pointer value.

int *p = &var; 

the identifier p designates object stores location of integer object. expression &var evaluates location (address) of object var. not lvalue; can't target of assignment (you can't update object's address). operand of unary & operator must lvalue. expression p, otoh, is lvalue since can assign new value it:

int y = 1; p = &y; printf( "%p\n", (void *) p );  // 1 of few places in c need cast void pointer 

the expression *p designates object p points to (in case, y). lvalue, since can assign object through it:

*p = 5;  // same y = 5 printf( "%d\n", *p ); 

so basically:

  • var, p, , y variables (identifiers designating objects)
  • var, p, *p, , y lvalues (expressions through object may read or modified)
  • &var, p, &p &y pointer expressions (expressions values locations of objects)
  • p pointer variable (object stores pointer value)

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -