answersLogoWhite

0

Multiple indirection in c language

Updated: 8/11/2023
User Avatar

Wiki User

16y ago

Best Answer

C uses pointers for indirection. So, using a pointer to a pointer would be multiple indirection. For example, the following code uses multiple indirection:

int i = 42;

int *pi = &i;

int **ppi = π

**ppi++;

printf("i is now %d\n", i);

User Avatar

Wiki User

16y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

The unary indirection operator (*) is used to dereference a pointer to a type or a function in order to convert it to an l-value or a function designator, respectively.

For instance, if you declare a pointer to an int type as follows:

int * i = new int(10);

Then i contains the memory address (typically 32-bit or 64-bit depending on the architecture) where the integer value 10 was allocated on the heap (the free store). To dereference this pointer to determine the value stored at that memory address, or indeed to alter the value at that memory location, we use the unary indirection operator, as follows:

if( *i == 10 )

*i = 5;

Note that the value of i has not changed -- it still contains the same memory address. But the value stored at that memory address will have been changed from 10 to 5. This can be proved by outputting both the value of i and the dereferenced value of i, both before and after changing the dereferenced value, such as:

int * i = new int(10);

printf( "Before:\n" );

printf( "Direct value of i: 0x%.8x, indirect value of i: %d\n\n", i, *i );

*i = 5;

printf( "After:\n" );

printf( "Direct value of i: 0x%.8x, indirect value of i: %d\n\n", i, *i );

Example output:

Before:

Direct value of i: 0x010255f3, indirect value of i: 10

After:

Direct value of i: 0x010255f3, indirect value of i: 5

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Access data via pointer. Eg:

*p, p->field

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

It's the arrow "->"

And the asterix "*"

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Multiple indirection in c language
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is indirection in c?

Accessing data via pointers.


What is indirection in c programming?

Example: *(int *)main = 5;


Why is multiple inheritance not possible in C?

C is not object-oriented -- you can't even use single inheritance let alone multiple inheritance.


What is problem in multiple inheritance?

Java does not support direct multiple Inheritance. Harder to implement, not every language support it: C++ does, Java does not.


C programs using loops?

Loops are very important part of a C-language. If we have to run our programe multiple time then we use Loops of C.


Why is it that c why is it that c plus plus best prog language?

C, and its successor, C++, are arguably the best language in certain scenarios. C and C++ are very portable (runs well on different platforms simply by compiling to different targets), have a decent trade-off of speed and portability, and, arguably, has the largest following of developers that use C and C++ on a regular basis; usually the first language ported to any new Operating System is C or C++. However, C and C++ are just tools; there are times when assembler is the best language, and yet others when Java or ActionScript is the best language. Learning multiple languages makes a developer far more versatile in today's market, and one should aspire to learn multiple languages if they wish to pursue a career as a developer.


Why c language has name c why not a?

C-language was derived from B-language.


What is previous language of c language?

language before c language is pascal


What is C language what does it do?

C Language is First Step of Programming Language, Help for C Language you are show the correct answer


What is accembly language?

Assembly language is a low level language where each statement (mostly) corresponds with one machine instruction. Higher level languages, such as C and FORTRAN, generate multiple machine instructions for each statement.


If A B and C are counting numbers and both A and B are multiples of C what can you say about A plus B?

A + B is also a multiple of C. ------------------------------------------- let k, m and n be integers. Then: A = nC as A is a multiple of C B = mC as B is a multiple of C → A + B = nC + mC = (n + m)C = kC where k = n + m kC is a multiple of C. Thus A + B is a multiple of C.


How do you output multiple 's on a single line in c plus plus programming language?

its supposed to have an asterisk there before the 's but it wouldnt print it