When you want to access an element, you have to first dereference your pointer, and then index the element you want (which is also dereferncing). i.e. you need to do:
printf("\nvalue:%c", (*ptr)[0]);
, which is the same as *((*ptr)+0)
Note that working with pointer to arrays are not very common in C. instead, one just use a pointer to the first element in an array, and either deal with the length as a separate element, or place a senitel value at the end of the array, so one can learn when the array ends, e.g.
char arr[5] = {'a','b','c','d','e',0}; char *ptr = arr; //same as char *ptr = &arr[0] printf("\nvalue:%c", ptr[0]);
Related Posts:
- Warning: assignment from incompatible pointer type
- Returning an array using C
- Why do I get “cast from pointer to integer of different size” error?
- Excess elements of scalar initializer for pointer to array of ints
- What exactly is meant by “de-referencing a NULL pointer”?
- Realloc Invalid Pointer in C
- Pointer to 2D arrays in C
- Pointer to a string in C?
- Pointer Arithmetic
- C pointers and arrays: [Warning] assignment makes pointer from integer without a cast
- What is the difference between const int*, const int * const, and int const *?
- Passing by reference in C
- Why does the arrow (->) operator in C exist?
- Difference between char* and const char*?
- #31 expression must have integral type
- How do you pass a function as a parameter in C?
- How to make an array with a dynamic size? General usage of dynamic arrays (maybe pointers too)?
- Constant pointer vs Pointer to constant
- Reversing a string in C
- waitpid, wnohang, wuntraced. How do I use these
- How to initialize array to 0 in C?
- Is the sizeof(some pointer) always equal to four?
- Sign extend a nine-bit number in C
- C: error: expected ‘)’ before ‘;’ token
- make: Nothing to be done for `all’
- How to printf a memory address in C
- What is the use of intptr_t?
- Data argument not used by format strings in C
- expected expression before ‘{‘ token
- Setting std=c99 flag in GCC
- C Vector/ArrayList/LinkedList
- warning: initializer element is not computable at load time
- error: ‘for’ loop initial declarations are only allowed in C99 mode [duplicate]
- c – warning: implicit declaration of function ‘printf’
- Flushing buffers in C
- What are 0x01 and 0x80 representative of in C bitwise operations?
- How to make parent wait for all child processes to finish?
- Undefined Reference issues using Semaphores
- What is time(NULL) in C?
- Use of cudamalloc(). Why the double pointer?
- char pointers: invalid conversion from ‘char*’ to ‘char’?
- Portable way to check if directory exists [Windows/Linux, C]
- OpenGL — GL_LINE_LOOP —
- How to use EOF to run through a text file in C?
- Incorrect checksum for freed object on malloc
- Valgrind complains with “Invalid write of size 8”
- Simple way to check if a string contains another string in C?
- What does “request for member ‘*******’ in something not a structure or union” mean?
- Segmentation fault (core dumped) due to fgets – I think
- What does “request for member ‘*******’ in something not a structure or union” mean?
- Unknown ending signal when using debugger gdb
- Valgrind: invalid read of size 4 -> sigsegv, works fine without valgrind and in visual studio
- How to convert integer to char in C?
- Is there a good Valgrind substitute for Windows?
- What’s the difference between * and & in C?
- Difference between “move” and “li” in MIPS assembly language
- How to empty a char array?
- What is the difference between array and enum in C ?
- Undefined reference to main – collect2: ld returned 1 exit status
- How can one see content of stack with GDB?
- What does the term “empty loop” refer to exactly in C and C++?
- Invalid type argument of -> C structs
- What does ** mean in C?
- Is there a way to have printf() properly print out an array (of floats, say)?
- What integer hash function are good that accepts an integer hash key?
- Proper way to empty a C-String
- malloc(): memory corruption
- How do you allow spaces to be entered using scanf?
- X86 assembly – Handling the IDIV instruction
- Pause screen at program completion in C
- Get size of pointer in C
- C: pointer to array of pointers to structures (allocation/deallocation issues)
- Difference between fgets and fscanf?
- Can’t understand the working of getint() in C as per K&R
- Lua – Number to string behaviour
- typedef struct pointer definition
- Reading in double values with scanf in c
- Difference between char* and char** (in C)
- What tools are there for functional programming in C?
- typedef fixed length array
- “-bash: gcc: command not found” using cygwin when compiling c?
- In C, what exactly happens when you pass a NULL pointer to strcmp()?
- What are the differences between if, else, and else if?
- Difference between the int * i and int** i
- strtok segmentation fault
- Invalid write of size 1
- How to solve static declaration follows non-static declaration in GCC C code?
- realloc(): invalid next size when reallocating to make space for strcat on char *
- Constructor for structs in C
- C Error: declaration shadows a local variable — Won’t let me repeatedly replace the value of my float variable
- MIPS to C Translation
- gdb: No symbol “i” in current context
- Cross Platform C library for GUI Apps?
- Implicit function declarations in C
- Pre increment vs Post increment in array
- Convert long long to string in C?
- How can I create a dynamically sized array of structs?
- how to stop a loop arduino
- How to normalize a mantissa
- Initialization makes pointer from integer without a cast – C