Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 704 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difference between variable and data object in C language?

#1
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.
Reply

#2
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.
Reply

#3
you already have answer but still if you want :

**Variables** : variables can be thought as name assigned for holder that refer to your actual object so when we say int x its just like a placeholder that refer to nothing (garbage value in c) but when we say int x=10; it initializes x with value 10 (now its refer to data object of type int also in this case name of data object will be maintained by compiler itself ) and we can use name x for accessing value 10.

**Data object** : as you quoted "Data object is a general term for a region of data storage that can be used to hold values." ie. memory location

**Pointers** : basically pointers are like variables which stores value but rather than storing an actual value (like int,float,char..) they hold address to memory location where your actual value is stored ie reference to data object.

"so when you say int x you say declare a placeholder named x of type int and when you say int *x you say declare a placeholder named x of pointer type that can hold reference to an int type."
Reply

#4
In C, an *object* is anything that takes up storage. [C 2011 online draft]( ):

<blockquote>
<strong>3. Terms, definitions, and symbols</strong><br>
...<br>
3.15<br>
1 <strong>object</strong><br>
region of data storage in the execution environment, the contents of which can represent values
</blockquote>

An *lvalue* is an expression that designates an object such that the contents of that object may be read or modified (basically, any expression that can be the target of an assignment is an lvalue). While the C standard doesn't define the term *variable*, you can basically think of it as any identifier that designates an object:

int var;

The identifier `var` designates an object that stores an integer value; the *expression* `var` is an lvalue, since you can read and/or modify the object through it:

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

A *pointer* is any expression whose value is the location of an object. A pointer *variable* is an object that stores a pointer value.

int *p = &var;

The identifier `p` designates an object that stores the location of an integer object. The *expression* `&var` evaluates to the location (address) of the object `var`. It is *not* an lvalue; it can't be the target of an assignment (you can't update an object's address). The operand of the unary `&` operator must be an lvalue. The expression `p`, OTOH, *is* an lvalue since you can assign a new value to it:

int y = 1;
p = &y;
printf( "%p\n", (void *) p ); // one of the few places in C you need to cast a void pointer

The expression `*p` designates the object that `p` *points to* (in this case, `y`). It is also an lvalue, since you can assign to the object through it:

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

So basically:

- `var`, `p`, and `y` are variables (identifiers designating objects)
- `var`, `p`, `*p`, and `y` are lvalues (expressions through which an object may be read or modified)
- `&var`, `p`, `&p` `&y` are pointer expressions (expressions whose values are locations of objects)
- `p` is a pointer variable (object that stores a pointer value)
Reply

#5
Data objects are the objects which stores data, the data objects in our computer are registers in Ram. Each register has an address location. Register has read_lock and write_ lock mechanism. In these registers you can store variable data and constant data. Variable data means it can modify in the entire process. Means, the Data objects which holds the variable data are called variables. To variables read_lock and write_lock are disabled. That's why you can modified the variables (variable data object) in your entire process. To identify the variable data objects you need to declare a name to it.
Ex: int speed: = 60;
Here speed is an variable(variable data object) it's size is 4 bytes. It holds the integer data only. The data in variables can changable in its entire application process.

In data objects if you store constant data those data objects are called contants. To constant data objects rd_lock is disabled but write_lock is enabled. That's why you can read the constants but can't able to assigne value to it.
To identify constants you need to declare a name to it.
Ex: int const speed = 100;
Here speed is a constant (constant data object). The data in speed can't changble in its entire application process.this speed holds data of interest type only.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through