What are pointers used for and how to use them?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What are pointers used for and how to use them??

I am not understanding pointers how it stores the address and other assignment and increment stuff

13th Sep 2019, 5:05 PM
Udith S M
Udith S M - avatar
2 Answers
+ 1
Pointers are variables that contain address of memory. That address usually points to the start of another variable or object. Incrementing the pointer is always done according to what it is pointing to. For example if ptr is pointer to int. And address is 0x0000 incrementing it by 1 will increase its value by 4 because thats how long int is and thats where next int would be found. 0x0004. Referencing non assigned memory will cause segfault. Meaning the operating system that is running your code will not allow it to access memory which it was not allocated. But thats whole another can of worms
13th Sep 2019, 6:10 PM
David Tsulaia
David Tsulaia - avatar