Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Notas de lectura

Pointers and data structures in c

Puntuación
-
Vendido
-
Páginas
22
Subido en
25-03-2023
Escrito en
2022/2023

Complete knowledge about pointers and data structures in an easy way.

Institución
Grado

Vista previa del contenido

Pointers

Introduction

 A pointer is a derived data type. This is the one which stores the address of data in memory, we will
be in position to access the data directly and do calculations over it.
 The standard concept is, access the data from memory using variable name it gets the data and
operations are done over them.
 But the pointer is different that the accessing is done by address the data is stored so that it will be
advantage of decreasing the instructions and overheads of standard usage.

Definition:

A pointer is a variable which contains the address of another variable.
Advantages of pointer

 Enables us to access a variable that is defined outside the function.
 Can be used to pass information back and forth between a function and its reference point.
 More efficient in handling data tables.
 Reduces the length and complexity of a program.
 Sometimes pointers also increases the execution speed.

Declaring of a pointer variable

General form:
data_type *pointer_name;
where,
• The asterisk (*) tells that the variable pointer_name is a pointer variable.
• Pointer_name is a identifier.
• pointer_name needs a memory location.
• pointer_name points to a variable of type data_type which may be int, float, double etc..
Example:




where
 ptr is not an integer variable but ptr can hold the address of the integer variable i.e. it is a pointer to an
integer variable’ ,but the declaration of pointer variable does not make them point to any location .
 We can also declare the pointer variables of any other data types .
For example:
double * dptr;
char * ch;
float * fptr;

,Dereference operator (*)
The unary operator (*) is the dereferencing pointer or indirection pointer , when applied to the
pointer can access the value the pointer points to.

Example:

int i= 15;
int * ptr;
ptr=&i;
printf(“Value of i is :%d”,i);
printf(“Address of i is :%d”,&i);
printf(“Value of i is :%d”,*ptr);
printf(“address of i is :%d”,ptr);
printf(“address of pointer is :%x”,&ptr);

Value of i is : 15
Address of i is : 1003
Value of i: 15
Address of i is : 1003
Address of ptr is : 2712

The null pointer
 Sometimes it is useful to make our pointers initialized to nothing . This is called a null pointer.
 A null pointer is the pointer does not point to any valid reference or memory address .We assign a
pointer a null value by setting it to address 0:
 Example
int *iptr;
iptr=0; or iptr = NULL;
 This statement assign address 0 to iptr . This statement describe a special preprocessor define called NULL
that evaluates to 0.
 Hence A null pointer is a pointer type which has a special value that indicate it is not pointing to any valid
reference.

Initialization of pointers
Initializing a pointer variable is a important thing, it is done as follows:
Step 1: Declare a data variable
Step 2:Declare a Pointer variable
Step 3:Assign address of data variable to pointer variable using & operator and assignment
operator.
Example:
int x;
int *p
p = &x;

, Pointer arithmetic

Pointer arithmetic operations are different from normal arithmetic operations.
The operations allowed to on Pointers are:
1. Add or subtract integers to/from a pointer. The result is a pointer.
2. Subtract two pointers to the same type. The result is an int.
3. Comparison of two pointers

Note: Multiplication, addition, division of two pointers not allowed.
1. Add or subtract integers to/from a pointer

 Simple addition or subtractions operations can be performed on pointer variables.
 If *iPtr points to an integer, *iPtr + 1 is the address of the next integer in memory after *iPtr. *iPtr
- 1 is the address of the previous integer before *iPtr
Examples:

int a=57; int a=57;
int *iptr=&a; iptr= iptr +1; iptr = iptr +(2B) iptr int *iptr=&a; iptr= iptr -1; iptr = iptr -(2B) iptr
=1003+2 =1003-2
iptr =1005 iptr =1001

Escuela, estudio y materia

Institución
Grado

Información del documento

Subido en
25 de marzo de 2023
Número de páginas
22
Escrito en
2022/2023
Tipo
NOTAS DE LECTURA
Profesor(es)
Dr karthik
Contiene
Todas las clases

Temas

$8.49
Accede al documento completo:

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Conoce al vendedor
Seller avatar
hemantkumar1

Documento también disponible en un lote

Conoce al vendedor

Seller avatar
hemantkumar1 nmit
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
-
Miembro desde
3 año
Número de seguidores
0
Documentos
7
Última venta
-

0.0

0 reseñas

5
0
4
0
3
0
2
0
1
0

Documentos populares

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes