Program 53 - CSU1128 - CSE 2026 - Shoolini University

Program to check the use of pointers an its use of address space

Explanation

The program checks the use of pointers and demonstrates the use of address space by displaying the value, address, and dereferenced value of a variable.

Header

The code begins with including the standard input-output header file using #include <stdio.h>.

Variable Declaration

The main() function is defined, and an integer variable d is declared:

  • int d;: Variable to hold the value entered by the user.

Program Description

The program prints a description message for the user to understand its functionality.

User Input

The user is prompted to enter the value of d:

  • printf("Enter the value: ");: Prompts the user to enter the value of d.
  • scanf("%d", &d);: Reads the value entered by the user and stores it in d.

Pointer Demonstration

The program demonstrates the use of pointers by printing the value, address, and dereferenced value of d:

  • printf("\n\n Number (d) is defined as %d. \n Its address (&d) is %p.\n Points to value at that address (*(&d)) is %i\n\n", d, &d, *(&d));: Prints the value of d, the address of d, and the dereferenced value of d.

Program End

The program ends with return 0; to indicate successful execution.

Code

                    
/*
 * -----------------------------------------------------------
 * Logic Building with Computer Programming (CSU1128)
 * Instructor: Dr. Pankaj Vaidya | Author: Divya Mohan
 * 
 * This code is a part of the educational initiative by dmj.one
 * with aim of empowering and inspiring learners in the field of
 * Computer Science and Engineering through the respective courses.
 * 
 * (c) 2022, Divya Mohan for dmj.one. All rights reserved.
 * -----------------------------------------------------------
 */

#include <stdio.h>

int main()
{
    printf("\n\n Program to check the use of pointers an its use of address space. \n\n");
    
    int d;
    printf("Enter the value: ");
    scanf("%d", &d);
    
    printf("\n\n Number (d) is defined as %d. \n Its address (&d) is %p.\n Points to value at that address (*(&d)) is %i
    \n\n", d, &d, *(&d));
    return 0;
}

                

Output

Program to check the use of pointers an its use of address space.

Enter the value: 54
Number (d) is defined as 54.
Its address (&d) is 0x7ffc31b70228.
Points to value at that address (*(&d)) is 54