C Programming : Pointer

Pointer to an array of function in C Programming !

#include<stdio.h> int display(); int(*arr[3])(); int(*(*ptr)[3])(); int main() { arr[0]=display; arr[1]=getch; ptr=&arr; printf(“%d”,(**ptr)()); (*(*ptr+1))(); return 0; } int display(){ int num = 25; return num; } Output : 25 Explanation : Step 1 : Array of Function int(*arr[3])(); above statement tell that - arr is an array of size 3. Array stores address of functions Array(…)

How to add two numbers using function pointer ?

How to add two numbers using function pointer ? #include<stdio.h> int sum (int n1,int n2); int main() { int num1 = 10; int num2 = 20; int result; int *(*ptr)(int,int); ptr = ∑ result = (*ptr)(num1,num2); printf(“Addition : %d”,result); return(0); } int sum (int n1,int n2) { return(n1 + n2); } Explanation : Write whole(…)

What is function Pointer ? | Pointer storing address of function.

What is function Pointer ? Function pointer : A pointer which keeps address of a function is known as function pointer. [ Visit : Complete Reference Document for Function Pointer ] Live Example : #include<stdio.h> void display(); int main() { void *(*ptr)(); ptr = &display; (*ptr)(); return(0); } void display() { printf(“Hello World”); } Output(…)

What is the difference between constant to pointer and pointer to constant?

What is the difference between constant to pointer and pointer to constant? No Pointer to Constant Constant Pointers 1 *ptr = 20 Statement is Invalid in Pointer to Constant i.e Assigning Value is Illegal *ptr = 20 is Absolutely Valid in Constant Pointers i.e Assigning Value is Perfectly legal 2 ptr ++ Statement is Valid(…)

What is Constant Pointers [ Const Pointer ] in C Programming ?

What is Constant Pointers [ Const Pointer ] in C Programming : As name suggests , Constant Pointers Cannot be modified . Modification in Integer to which it Points to is Allowed Modification made in Pointer is Not Allowed Syntax Declaration : data_type * const Pointer_name = Initial_Address; Sample Code Snippet : int num =(…)

Pointer to Constant Objects | const int pointer in C Programming

Pointer to Constant Objects : Pointer to a Constant Object is called as ‘Pointer to Constant Object’ Syntax : const data-type *pointer_name ; Example : int n = 30 ; const int ptr; ptr = &n; What does it means ? “const int” means integer is constant. We cannot change value of the integer. Pointer(…)

Pointer to Pointer | Double pointer in C Programming

Pointer to Pointer in C Programming Declaration : Double Pointer int **ptr2ptr; Consider the Following Example : int num = 45 , *ptr , **ptr2ptr ; ptr = # ptr2ptr = &ptr; What is Pointer to Pointer ? Double (**) is used to denote the double Pointer Pointer Stores the address of the Variable Double(…)

Differencing or Subtracting two Pointer in C Programming Language

Differencing Pointer in C Programming Language : Differencing Means Subtracting two Pointers. Subtraction gives the Total number of objects between them . Subtraction indicates “How apart the two Pointers are “ Example : #include<stdio.h> int main() { int num , *ptr1 ,*ptr2 ; ptr1 = &num ; ptr2 = ptr1 + 2 ; printf(“%d”,ptr2 -(…)

Comparison of two Pointers | Comparing two pointer Variables

Comparison between two Pointers : Pointer comparison is Valid only if the two pointers are Pointing to same array All Relational Operators can be used for comparing pointers of same type All Equality and Inequality Operators can be used with all Pointer types Pointers cannot be Divided or Multiplied Point 1 : Pointer Comparison #include<stdio.h>(…)

Subtracting integer value from Pointer

Suppose we have subtracted “n” from pointer of any data type having initial addess as “init_address” then after subtraction we can write - ptr = initial_address - n * (sizeof(data_type)) Subtracting integer value with Pointer int *ptr , n; ptr = &n ; ptr = ptr - 3; Live Example 1 : Decrement Integer Pointer(…)