Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
3.1k views
in GTU B.E. (CSE-I-Sem) Programming For Problem Solving Lab by Goeduhub's Expert (7.1k points)

Write a C program to print the address of character and the character of string using pointer

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 360/- || For International Students- $9.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence || Labeled as Highest Rated Course by Udemy

Apply Coupon

2.

Complete Machine Learning & Data Science with Python| ML A-Z Apply Coupon

3.

Complete Python Programming from scratch | Python Projects Apply Coupon
    More Courses

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.1k points)
edited by
 
Best answer

Print Address of Character and String Using Pointers

In this program we are going to print address of character and string using pointers. As we know a string is a stream of characters and each character holds different address. So to print address of each character's address we are going to take a pointer array to hold address of each character as in the following example.

Example :

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{

//Declaration and initialization of character and string
char str[30]="Goeduhub Technologies";
char c='A';
int i;
//Declaration and assignment of pointers
char *ptr_str[30];
char *ptr_c=&c;

//Assigning address of each character of string to pointer array
for(i=0;i<strlen(str);i++)
ptr_str[i]=&str[i];


//Printing value and address of variables on output window
printf("\nString Entered is : %s\n Address of string :",str);
for(i=0;i<strlen(str);i++)
printf("\n%c's address : %p",str[i],ptr_str[i]);
printf("\nValue of c = %c\nAddress of c = %p",c,ptr_c);
getch();
}

Output :

Output of above program showing address of string using pointer


For More GTU C Programming Lab Experiments Click Here

3.3k questions

7.1k answers

394 comments

4.6k users

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...