In this tutorial you will learn about the C Program to print Address of Variable and its application with practical example.
C Program to print Address of Variable
In this tutorial, we will learn to create a C program that will Print the Address of the variable in C programming.
Prerequisites
Before starting with this tutorial we assume that you are best aware of the following C programming topics:
- Operators in C Programming.
- Basic Input and Output function in C Programming.
- Basic C programming.
Print the Address of the variable.
As we all know the c programming is a very powerful language. In the c programming language, we have many pre-defined functions for arithmetic operations, string functions. But today we will print the address of the variable taken input from the given number using the c programming language.
With the help of this program, we can Print the Address of the variable.
Algorithm:-
1 2 3 4 5 6 7 8 9 |
1. Declare the variables for the program. 2. Take the input number from the user. 3. Print the number. 4. Print the address. 5. End the program. |
Program to Print the Address of variable:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
/* C Program to print Address of Variable */ #include<stdio.h> int main() { //declaring the variable for the program int no1, no2, no3, sum=0; /* sending message on the console to take a number1 in input on a variable */ printf("Enter any number to store in \"no1\" variable: "); scanf("%d", &no1); /* sending message on the console to take a number2 in input on a variable */ printf("Enter any number to store in \"no2\" variable: "); scanf("%d", &no2); /* sending message on the console to take a number3 in input on a variable */ printf("Enter any number to store in \"no3\" variable: "); scanf("%d", &no3); //printing the value of the variable1 printf("\nValue of no1 = %d", no1); //printing the address of the variable1 printf("\nAddress of no1 = %u", &no1); //printing the value of the variable 2 printf("\nValue of no2 = %d", no2); //printing the address of the variable 2 printf("\nAddress of no2 = %u", &no2); //printing the value of the variable 3 printf("\nValue of no3 = %d", no3); //printing the address of the variable 3 printf("\nAddress of no3 = %u", &no3); sum = no1+no2+no3; //printing the value of the variable sum printf("\n\nValue of sum = %d", sum); //printing the address of the variable sum printf("\nAddress of sum = %u", &sum); return 0; } |
Output:-
In the above program, we have first initialized the required variable.
- no1 = it will hold the integer value of number input.
- no2 = it will hold the integer value of number input.
- no3 = it will hold the integer value of number input.
- sum = it will hold the integer value of number input.
Display message to Take input number from the user and scan the input number.
Program code to print the data and address of the given number.