can any one explain in detail about the following program of pointers in c?

Subrahmanyam Janapamula
void main(){
   char a[2][30]={"Don't walk in front of me..", "I am not follow"};
   printf("%c%c", *(a[0]+9), *(*(a+0)+5));
}

And the output of the program is

k
code_fodder

Some example based explanations...

c-arrays can be accessed in two ways:

As an array:

char a[10] = "0123456789";
printf("%c", a[5]); // prints "5"

As a pointer:

char a[10] = "0123456789";
printf("%c", *(a + 5)); // prints "5"

In the second example we are just dereferencing a as a pointer to the start of the string plus 5.

This can be used for 2d, 3d, etc... arrays as well:

char a[2][10] = {"012", "abc"};
printf("%c", *(*(a + 0)+1)); // prints "1"
printf("%c", *(*(a + 1)+1)); // prints "b"

You can mix the two methods:

printf("%c", *(a[0] + 1); // prints "1"
printf("%c", *(a + 1)[1]; // prints "b"

And just for completeness (this could be considered the "normal" way to access the array values):

printf("%c", a[0][1]; // prints "1"
printf("%c", a[1][1]; // prints "b"

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Explain the output of the following C program?

Can some explain the performance behavior of the following memory allocating C program?

Can anyone explain and trace the following multiple recursive C program?

Can any one explain this strange behavior about Array sort?

Can any one explain this go program which uses a method expression

Can you explain why will be output by executing the following C code such that :'d c c d'?(pointers)

Can anyone explain the output of this program based on pointers?

Can anyone explain what is the error in the following program?

Can anyone please explain the output of the following program

Can anyone explain in detail the following two commands regular expressions

Explain me the following C program's output

Please explain the output of the following C program.

Can any one explain me how the size get allocated in the following case?

Please explain the following code in detail

A strange behavior about pytorch tensor. Any one can explain it clear?

Can someone explain following type casting in C?

Can someone explain the following C++ Syntax?

Can any one explain Screenshot in Selenium?

Friends Can any one explain this code

Can any one explain the logic behind this code

can someone explain this equation to me from the c program about generating prime number till 100

Can some one explain me the following Java snippet for recursion?

Can you please explain the output of this C program?

Can someone explain the output of this c++ program?

Can someone please explain the output of this C program?

Can someone explain the output of this program written in C

Output of below program show A=30, B-30 and C=30 any on can explain why not A=10, B=20 and C=30?

I'm new to c++ can you explain pointers in this instance

Can any one help Type 'Observable<Detail>' is missing the folowing problem?