C Programming language

C Standard Library Function

Day 1: Introduction and brief history of C Programming language

Day 1: Advantages and Disadvantages of C, C Keywords, Data type modifiers in C

Day 1: Data types in C Programming language

Day 1: Secondary data types, Primitive and Non-primitive data types

Day 1: C Variables, C Constant, Format Specifiers in C

Day 2: Write first C program

Day 2: Flow of C program with example, main(), printf(), scanf()

Day 2: Operaters in C Programming language, Arithmetic operators

Day 2: Relational operators and Logical Operators in C Programming language

Day 2: Assignment, Increments and Decrement Operators in C Programming language

Day 3: Conditional statement: if else statement in C Programming language

Day 3: Conditional statement: switch statement in C Programming language

Day 3: Jump statements: return statement in C Programming language

Day 3: Jump statements: go to statement in C Programming language

Day 3: Jump statements: break statement in C Programming language

Day 3: Jump statements: continue statement in C Programming language

Day 4: Loops OR Iteration statement in C Programming language: for Loop

Day 4: Loops OR Iteration statement in C Programming language: while Loop

Day 4: Loops OR Iteration statement in C Programming language: do while Loop

Day 5: Array in C Programming language

Day 5: Access elements of Array in C Programming language

Day 5: One dimensional Array representation in memory using C Programming language

Day 5: Two dimensional Array representation in memory using C Programming language

Day 5: Multidimensional Array in C Programming language

Day 6: Function in C Programming language

Day 6: Definition, Declaration and Calling a Function in C Programming language

Day 6: Passing array to a function in C Programming language

Day 6: Calling Function in C Programming language : Call by value

Day 6: Calling Function in C Programming language : Call by reference

Day 6: Recursive Function in C Programming language

Day 6: Adding function to the library in C Programming language

Day 7: Pointer in C Programming language, How to use Pointer, Pointer declaration

Day 7: NULL Pointers in C Programming language

Day 7: Array of Pointers in C Programming language

Day 7: Pointer arithmetic in C Programming language

Day 7: Pointer to Pointer in C Programming language

Day 7: Pointer to Function in C Programming language: Passing pointers to functions

Day 7: Pointer to Function in C Programming language: Return pointer from functions

Day 8: Strings in C Programming language, Declaring String in C Programming language

Day 8: String functions in C Programming language

Introduction of Structure

Accessing the members of Structure

Structure With typedef Keyword and Use of sizeof function

Example of Structure

Dynamic memory allocation in C: Introduction

adplus-dvertising
Day 7 Pointer in C Programming language, Pointer declaration
Previous Home Next

# Pointer

In c a pointer is a variable that points to or references a memory location in which data is stored. Each memory cell in the computer has an address that can be used to access that location so a pointer variable points to a memory location we can access and change the contents of this memory location via the pointer.

Pointer is a address variable that hold the address of another variable. We can have a pointer to any variable type. The & is a unary operator that gives the address of a variable. The * (indirection or dereference operator), that gives the contents of an object that pointed to by a pointer.

(&) Ampersand operator

//Using & operator show the address of variable

void main( )
{
	int a = 5 ;
	printf ( "\nAddress of a = %u", &a );
	printf ( "\nValue of a = %d", a );
}
Output

Address of a=1444

Value of a=5

How to use Pointer, Pointer declaration

Note: In above example variable a memory address is 1444. Means using this & we find the memory address.

Syntax

data_type_name *variable_name  

int *ptr; //Declare a pointer

# Now using pointer, once we declare a pointer variable we must point it to something we can do this by assigning to the pointer the address of the variable like:

To access memory address of variable x you have to use pointer. To declare pointer you use asterisk notation (*) after pointer's data type and before pointer name as follows:

int x = 10;

/* Now  pointer ptr to points to memory address of variable x */
const int *ptr;

/* you can use address-of operator (&) */
ptr = &x;

/* Show address of variable x */
printf("Address of x is %d\n", ptr); 

/* Variable x */
printf("Value of x is %d\n", *ptr); 

/* you can change the content of variable x 
using poiter variable */

*ptr += 10;// Increasing the value
printf("Value of x after increasing %d\n",x);

*ptr -= 5;// Decreasing the value
printf("Value of x after decreasing %d\n",x);
Output:

Address of x is 1310580

Value of x is 10

Value of x after increasing 20

Value of x after decreasing 15

Previous Home Next