Lecture 15: String problem statements and Pointers in C Language
String problem statements and Pointers in C Language: Basic concept of pointers: Pointer is a variable which holds the memory address of another variable of same data type. Pointer operator available in C is ‘*’, called ‘value at address’ operator. It gives the value stored at a particular address. The ‘value at address’ operator is also called ‘indirection’ operator also. Let variable declaration is given as follows, int x = 5 ; This above declaration tells the C compiler to: 1. Reserve space in stack memory to hold the integer value. 2. Associate the name x with this memory location. 3. Store the value 5 at this location. There are two important notations associated with pointers: 1. Address of operator that is & gives you address of a variable. 2. Value at the address location that is dereference operator * gives you value at that address location. Integer pointer type of variable stores address of another integer type of variable but not float or double. Pointer variable may be type of int, char, array, structure, function or any other pointers. For examples: 1. Pointer p which is storing memory address of an int type variable: int i=50; int *p; p=&i; 2. Pointer p which is storing memory address of a float type variable: float i=21.21; float *p; p=&i; 3. Pointer p which is storing memory address of an array: int arr[20]; int *ptr; ptr= arr; // Name of array itself gives you base address of array 4. Pointer p which is storing memory address of a structure: struct student s; struct student *p; P = &s; 6.2. Pointer declaration and initialization: Let us see the declaration of a pointer variable. When we want to store address of a particular variable we make use of ‘& ‘ and ‘* ‘ operator explicitly as follows: int x; //value variable declaration int *y; //pointer declaration The purpose of pointer variable is that we can store the address of another variable into it. x=5; //value variable initialization y =&x; //pointer initialization In c programming every variable having two types of values. 1. Content or data of variable or value of variable. 2. Address of variable where it is stored in the memory. Meaning of following simple pointer declaration and definition: int a=21; //value variable initialization int * ptr; //pointer declaration ptr=&a; //pointer initialization Explanation: About variable a: 1. Name of variable: a 2. Value of variable which it keeps: 21 3. Address where it has stored in memory: 6565 (assume) About pointer type variable ptr: 4. Name of variable: ptr 5. Value of variable which it keeps: 6565 6. Address where it has stored in memory: 7575 (assume) 6.3. Use of ‘&’ operator called as address of operator and ‘*’ operator: The expression &i gives the address of the variable i on the RAM and *p gives you value at that address location. C Learning App: C Language Basics App Easy to Understand C Learning app helps you in learning C language with suitable programs and MCQs. To learn other languages such as C++, Java, C# it is mandatory to learn C first. This app provides the basics and advanced concepts of the C in easy and simple way. Also, examples are provided for proper understanding of concepts with appropriate clarification. This app covers utmost of the scenario’s programs along with outputs. C Learning app categories: 1. Basic Concepts 2. Programing Examples Please install my new C Learning App. Link: https://play.google.com/store/apps/details?id=com.siddhi.CLearningApp&hl=en_IN&fbclid=IwAR0B43sceJQ5k6p6DYCHjKwXn3SYZD3k3dskmlQ0jJuiO84i96DxzNjQcWk Thanks to All. Prof. Amol M. Jagtap M.Tech CSE 7972761065 Please like comment share and subscribe. Prof. Amol M. Jagtap For more contact : 7972761065
Download
0 formatsNo download links available.