answersLogoWhite

0

AllQ&AStudy Guides
Best answer

Pa draig O Ri agai n has written:

'The Gaeltacht studies'

This answer is:
Related answers

Pa draig O Ri agai n has written:

'The Gaeltacht studies'

View page

c o n p u e

View page

44,.,,JNJBNJ

View page

Dereferencing a pointer returns the value stored at the memory location being pointed at, according to the type of pointer.

Consider the following code. c is a char type and p is a pointer to a char type. c is assigned the value 'X' (88 decimal, 0x58 hexadecimal) while p is assigned the address of c, using the addressof operator &.

The remainder of the code prints the address and value of both c and p, and also the dereferenced value of p. Note that you cannot dereference c since it is an alias for a reference, not a pointer to a reference.

Note how the value of p is the memory address of c, while the dereferenced value of p is the value of p. note also that pointers are variables like any other, and therefore occupy memory of their own, as shown by the address of p.

#include

using namespace std;

int main()

{

char c = 'X';

char * p = &c;

printf( "Address and value of c:\n" );

printf( "&c = 0x%.8x\n", &c );

printf( " c = 0x%.2x (%u) '%c'\n", c, c, c );

cout << endl;

printf( "Address, value and dereferenced value of p:\n" );

printf( "&p = 0x%.8x\n", &p );

printf( " p = 0x%.8x\n", p );

printf( "*p = 0x%.2x (%u) '%c'\n", *p, *p, *p );

cout << endl;

return( 0 );

}

View page

appliance

View page
Featured study guide
📓
See all Study Guides
✍️
Create a Study Guide
Search results