Computer Programming C Laboratory: Pointers C Programs

Write a C program to print the value and the address of the element using pointer (Using Pointer and Array)

Using Pointers and Arrays - C Programming

Write a C program to print the value and the address of the element using pointer.

* C Program to print the value and the address of the element using pointer */

#include <stdio.h>

main()

{

int arr[5]={10,20,30,40,50}; /* arr[5] has five elements of integer data type */

int i,*p_arr;    /* i,*p_arr is a pointer variables */

p_arr=arr;

for(i=0; i<=5;i++)

{

        printf("Address=%u", &arr[i]);

        printf("Element=%d", &arr[i]);

        printf("%d", *(arr+i));

        printf("%d",p_arr[i]);

        printf(“%d”, *(p_arr+i));

} /* for */

} /* main */

OUTPUT

Address 4000 Element 10 10 10 10

Address 4002 Element 20 20 20 20

Address 4004 Element 30 30 30 30

Address 4006 Element 40 40 40 40

Address 4008 Element 50 50 50 50

EXPLANATION: In the above program, the variable arr[] is declared as integer array, the elements are displayed using different syntax. (1) &arr[i], (2) *(arr+i), (3) p_ (4) *(p_arr+i).

1) &arr[i] ‒ This prints 0th address elements from the array.

2) *(arr+i) ‒ The arr+i is addition of a constant with the base address of an array. It shows the address of element. The *(arr+i) points to the elements of an array.

3) p_arr[i] ‒ Here 'p_arr' refers to the element number and i refers to the base address. By varying p_arr and i the various elements of the array are displayed.

4) *(p)arr+i) ‒ This statement is same as 2.


Computer Programming C Laboratory: Pointers C Programs : Tag: C Programming : - Write a C program to print the value and the address of the element using pointer (Using Pointer and Array)


Computer Programming C Laboratory: Pointers C Programs



Under Subject


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation



Related Subjects


English Essentials I

EN25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


தமிழர் மரபு - Heritage of Tamils

UC25H01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Calculus

MA25C01 Maths 1 M1 - 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I

PH25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Applied Chemistry I

CY25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Makerspace

ME25C04 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming C

CS25C01 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Computer Programming Python

CS25C02 1st Semester | 2025 Regulation | 1st Semester 2025 Regulation


Fundamentals of Electrical and Electronics Engineering

EE25C03 1st Semester EEE Depart | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Mechanical Engineering

ME25C03 1st Semester Mechanical Dept | 2025 Regulation | 1st Semester 2025 Regulation


Introduction to Civil Engineering

CE25C01 1st Semester Civil, Agri Departments | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing

CS25C03 1st Semester - AIDS, CSE, CSE(CY), IT Department | 2025 Regulation | 1st Semester 2025 Regulation


Applied Physics I Laboratory

PH25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Applied Chemistry I Laboratory

CY25C01 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming C Laboratory

CS25C01 1st Semester EEE, ECE, CSE, CSE(CY), AIDS, IT practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Computer Programming Python Laboratory

CS25C02 1st Semester practical Laboratory Manual | 2025 Regulation | 1st Semester Laboratory 2025 Regulation


Engineering Drawing

ME25C01 EEE, Mech, Agri, EEE Depts | 2025 Regulation | 2nd Semester 2025 Regulation


Basic Electronics and Electrical Engineering

EE25C04 1st Semester ECE Dept | 2025 Regulation | 1st Semester 2025 Regulation


Essentials of Computing - Laboratory

CS25C03 1st Semester AIDS, CSE, CSE(CY), IT Depts | practical Laboratory Manual | 2025 Regulation | 1st Semester 2025 Regulation