clanguage07@gmail.com

clanguage07@gmail.com

Sunday, September 8, 2013

Pointer to array of string in c programming


Pointer to array of string: A pointer which pointing to an array which content is string, is known as pointer to array of strings.


What will be output if you will execute following code?


#include<stdio.h>
int main(){

char *array[4]={"c","c++","java","sql"};
char *(*ptr)[4]=&array;
printf("%s ",++(*ptr)[2]);


return 0;
}

Output: ava
Explanation:

In this example

ptr: It is pointer to array of string of size 4.

array[4]: It is an array and its content are string.
Pictorial representation:







Note: In the above figure upper part of box represent content and lower part represent memory address. We have assumed arbitrary address.

++(*ptr)[2]
=++(*&array)[2] //ptr=&array
=++array[2]
=++”java”
=”ava” //Since ptr is character pointer so it
// will increment only one byte

Note: %s is used to print stream of characters up to null (\0) character.

No comments:

Post a Comment

GET MORE INFORMATION

http://ads.qadservice.com/t?id=c2168e05-8974-4816-872a-91936ff7379d&size=1024x768&drct=true