In C programming, pointers is variable that hold memory addresses of another variable. However, the way pointers work with different data types can be confusing for me
Code:
#include <stdio.h>#include <stdlib.h>
int main() {
// Assigning a string to the pointer 'y'
char *y = "abcd"; // confued in this line
printf("%s\n", y); // Output: "abcd"
// Assigning a value of 10 to the pointer 'x'
int num = 10; // Define an integer variable 'num'
int *x = # // 'x' points to the address of the integer variable 'num'
printf("%d\n", *x); // Output: 10
return 0;
}
I understand that a string in C is an array of characters,I'm curious to know the underlying reason and the logic behind this distinction. If anyone could shed some light on this topic, I'd greatly appreciate it