C Online Compiler
Example: Access Array Elements using Array Name as Pointer in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Access Array Elements using Array Name as Pointer #include <stdio.h> int main() { // Step 1: Declare and initialize an array char message[] = {'H', 'e', 'l', 'l', 'o', '\0'}; // C-style string int size = sizeof(message) / sizeof(message[0]); // Step 2: Access elements using the array name directly as a pointer printf("Accessing elements using array name as a pointer:\n"); for (int i = 0; i < size; i++) { printf("Character at index %d: %c\n", i, *(message + i)); } // You can also print the whole string using the array name as a pointer printf("\nFull message: %s\n", message); return 0; }
Output
Clear
ADVERTISEMENTS