C67. const pointer and pointer to a constant

Опубликовано: 09 Май 2026
на канале: Tech Courses
124
14

In this video we are going to discuss about const pointer and pointer to a constnat in C.

Summary :
Const Pointer means we cannot change pointer to point to another variable.
int i = 10;
int j = 20;
int *const ptr = &i; // ptr is a const pointer to an int
*ptr = 30; // Valid, can change value pointed by pointer
ptr = &j; // Invalid, cannot point to another variable

Pointer to a const means we cannot change value pointed by pointer.
int i = 10;
int j = 20;
const int *ptr = &i; // ptr is a pointer to a const int
*ptr = 30; // Invalid, cannot change value pointed by pointer
ptr = &j; // Valid, can point to another variable

Const Pointer to a const means we cannot change value pointed by pointer.
Also we can not change pointer to point to another variable.
int i = 10;
int j = 20;
const int *const ptr = &i; // ptr is a const pointer to a const int
*ptr = 30; // Invalid, cannot change value pointed by pointer
ptr = &j; // InValid, cannot point to another variable


Audio language : Hindi
In this course , we are going to cover all C concepts in simple and easy to understand terms.
This course will start from basics and later on we will cover advance topics that are important from interview point of view.

Github : https://github.com/TechCourses4u/C-La...
Programs :
https://github.com/TechCourses4u/C-La...