Pointers in C : Example 7
Автор: focal point
Загружено: 2020-08-26
Просмотров: 9
Описание:
A pointer is a VARIABLE. Pointers store the address of variables or a memory location.
#GATE_2021, #GATE , #GATE_PREPARATION
GENERAL SYNTAX::
datatype *var_name;
EXAMPLE::
int *ptr;
To use pointers in C, we must understand below two operators.
To access the address of a variable to a pointer, we use the unary operator & (ampersand) that returns the address of that variable. For example, &x gives us the address of variable x.
One more operator is unary * (Asterisk) which is used for two things :
To declare a pointer variable: When a pointer variable is declared in C, there must be a * before its name.
To access the value stored in the address we use the unary operator (*) that returns the value of the variable located at the address specified by its operand. This is also called Dereferencing.
POINTER EXPRESSION AND POINTER ARITHMETIC
A limited set of arithmetic operations can be performed on pointers. A pointer may be:
incremented ( ++ )
decremented ( — )
an integer may be added to a pointer ( + or += )
an integer may be subtracted from a pointer ( – or -= )
Pointer arithmetic is meaningless unless performed on an array.
Note: Pointers contain addresses. Adding two addresses makes no sense because there is no idea what it would point to.
Subtracting two addresses lets you compute the offset between these two addresses.
ARRAY NAME AS POINTER
An array name acts like a pointer constant. The value of this pointer constant is the address of the first element.
For example, if we have an array named val then val and &val[0] can be used interchangeably.
BENEFITS OF USING POINTERS
Pointers are more efficient in handling Arrays and Structures.
Pointers allow references to function and thereby helps in the passing of function as arguments to other functions.
It reduces the length of the program and its execution time as well.
It allows C language to support Dynamic Memory management.
#GATE_2021, #GATE , #GATE_PREPARATION , #focalpoint , #gateexam, #gate_cs , #focalpoint , #gateexam , #gate_cse
Gate cse videos
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: