Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Basics of C programming, Study notes of Computer Science

Fundamental of C programming/ lecture notes/ Study material/ batch 2024

Typology: Study notes

2023/2024

Available from 09/04/2024

SathyapriyaAshok
SathyapriyaAshok 🇮🇳

3 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Basics of C programming and more Study notes Computer Science in PDF only on Docsity!

UNIT -5 POINTERS 1. INTRODUCTION & UNDERSTANDING POINTERS Pointers are one of the core components of the C programming language. A pointer can be used to store the memory address of other variables, functions, or even other pointers. The use of pointers allows low-level memory access, dynamic memory allocation, and many other functionality in C. What is a Pointer in C? A pointer is defined as a derived data type that can store the address of other C variables or a memory location. We can access and manipulate the data stored in that memory location using pointers. As the pointers store the memory addresses, their size is independent of the type of data they are pointing to. This size of pointers only depends on the system architecture. Syntax The syntax of pointers is similar to the variable declaration in C, but we use the ( * ) dereferencing operator in the pointer declaration. datatype * ptr; where ¢ ptr is the name of the pointer. ¢ datatype is the type of data it is pointing to. The above syntax is used to define a pointer to a variable. We can also define pointers to functions, structures, etc. How to Use Pointers? The use of pointers can be divided into three steps: 1. Pointer Declaration 2. Pointer Initialization 3. Dereferencing Pointer Declaration In pointer declaration, we only declare the pointer but do not initialize it. To declare a pointer, we use the ( * ) dereference operator before its name. Example int *ptr; The pointer declared here will point to some random memory address as it is not initialized. Such pointers are called wild pointers.