Confusion char * notes [] = {"Ab", "F #", "B", "Gb", "D"}; and char **

I really confuse the definition of this type of pointer:

char *notes[] = {"Ab", "F#", "B", "Gb", "D"};`. 

I understand that noteshere is an array of char pointers, which, as I understand it, as elements of notes, should be the addresses of char typed variables. Where am I mistaken? So how does it work?

#include<iostream>
#include<string>

using namespace std;

int main()
{
    char *notes[] = {"Ab", "F#", "B", "Gb", "D"};
    cout << *(char**)(notes+2);
}

And what does it do char**and what is its significance?

+4
source share
4 answers

In this sense, char *notes[]means notes[]- an array pointer to char

This means that it nodesis an array char*, i.e. an array of character pointers.

notes[] char .

C (.. , ) C . .

, :

Address Value Character
------- ----- ---------
1000000    65 A
1000001    98 b
1000002    00 NULL terminator
1000003    70 F
1000004    35 #
1000005    00 NULL terminator
1000006    66 B
1000007    00 NULL terminator
1000008    71 G
1000009    98 b
1000010    00 NULL terminator
1000011    68 D
1000012    00 NULL terminator

:

notes = {1000000, 1000003, 1000006, 1000008, 1000011};

: - . .

+8

:

char *nodes[] nodes[] - char

. char *nodes[] , nodes - , .

+4
char *notes[]

char.

char **notes 

char, , char *notes[], , , .

: , "Ab" "F #", , char * note = "Ab" , note char , .

So char *notes[] - , char **notes, , , .

+3

, * :

  • .
    : int *p - p int

  • else :
    : *p = 6 - , , p, 6

:

char *notes[] = {"Ab", "F#", "B", "Gb", "D"}

notes 5 ( ) char * ( char)

"asdf"- string literal. The string literal is of type char [](C) / const char [](C ++). (an array of [persistent] characters) that can break up into pointers: in some context, can be added to char *(unfortunately, falling is allowed const, but this is another possibility for worms)

+1
source

Source: https://habr.com/ru/post/1598275/


All Articles