What is the difference between “char a” and “char a[1]”?
Question Source: Aricent Interview
Although both expressions can be used to create a variable to store one character, there are following differences.
1) “char a” represents a character variable and “char a[1]” represents a char array of size 1.
2) If we print value of char a, we get ASCII value of the character (if %d is used). And if we print value of char a[1], we get address of the only element in array.
#include <stdio.h> int main () { char a1 = 'A'; char a2[1] = {'A'}; printf("%d %d", a1, a2); return 0; } |
chevron_right
filter_none
Output:
65 An address
This article is contributed by Abhishek. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- Difference between C and C++
- Difference between ++*p, *p++ and *++p
- Difference between scanf() and gets() in C
- Difference between while(1) and while(0) in C language
- Difference between C and Python
- Difference between strncmp() and strcmp in C/C++
- Difference between Java and C language
- Difference between Structure and Array in C
- Difference between while and do-while loop in C, C++, Java
- Difference between Structure and Union in C
- Difference between fork() and exec()
- Difference between float and double in C/C++
- Difference between pointer and array in C?
- Difference between Static and Shared libraries
- Difference between Header file and Library



