C Pointers: Guide to Understanding & Using | Boredzo.org

  • Thread starter R A V E N
  • Start date
  • Tags
    Pointers
In summary, pointers in C are variables that store the memory address of another variable and allow for direct access and manipulation of memory locations. To declare and initialize a pointer, you use the * symbol and assign it the memory address of another variable using the & symbol. To access the value of the variable pointed to by a pointer, you use the * symbol before the pointer name. It is also possible to have a pointer to a pointer, known as a double pointer. Pointers are crucial in dynamic memory allocation in C, as they allow for the allocation of memory at runtime using the malloc() function.
Technology news on Phys.org
  • #2
Maybe someone finds this PDF more easy to understand:
 

Attachments

  • pointers_explained.pdf
    67.2 KB · Views: 382
  • #3
Whoo that is a nice explantation, for new c/c++ programmers, because more and more people come from langiages like java or c# and always find pointers confusing.

i wish i had that explanation back in the learning days :P
 
  • #4
Or this one PDF,it`s more detailed:

By the way,Google gives this page as first result on "C pointes explained".:tongue2:
 

Attachments

  • pointers.pdf
    183.8 KB · Views: 310
Last edited:
  • #5
Great article to explaine "Pointer" for beginners.
 

1. What are pointers in C and what is their purpose?

Pointers in C are variables that store the memory address of another variable. Their purpose is to allow for direct access and manipulation of memory locations, making it possible to create more efficient and flexible programs.

2. How do you declare and initialize a pointer in C?

To declare a pointer in C, you use the * symbol before the variable name. For example: int *ptr; To initialize a pointer, you assign it the memory address of another variable using the & symbol. For example: ptr = # where num is the variable whose address you want to store in the pointer.

3. How do you use a pointer to access the value of the variable it points to?

To access the value of the variable pointed to by a pointer, you use the * symbol before the pointer name. For example: *ptr will give you the value stored at the memory address stored in the pointer.

4. Can you have a pointer to a pointer in C?

Yes, you can have a pointer to a pointer in C. This is known as a double pointer and it is used when you want to point to a pointer. It is declared using the ** symbol before the variable name and can be initialized with the address of another pointer.

5. How are pointers used in dynamic memory allocation?

Pointers are essential in dynamic memory allocation in C. They allow you to dynamically allocate memory at runtime, which means you can allocate memory for variables based on user input or other conditions. This is done using the malloc() function, which returns a pointer to the allocated memory, and the * symbol is used to access the value stored at that memory address.

Similar threads

  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
5
Views
883
  • Programming and Computer Science
2
Replies
40
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
7
Views
3K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
2
Views
931
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
3
Views
726
  • Programming and Computer Science
Replies
17
Views
1K
Back
Top