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; } |
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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Difference and Similarities between PHP and C
- Difference Between malloc() and calloc() with Examples
- What is the difference between single quoted and double quoted declaration of char array?
- Difference between "int main()" and "int main(void)" in C/C++?
- Difference between ++*p, *p++ and *++p
- Difference between pointer and array in C?
- What’s difference between header files "stdio.h" and "stdlib.h" ?
- What is the difference between printf, sprintf and fprintf?
- Difference between getc(), getchar(), getch() and getche()
- What’s difference between “array” and “&array” for “int array[5]” ?
- What's difference between char s[] and char *s in C?
- Difference between C structures and C++ structures
- Difference between Structure and Union in C
- Difference between strlen() and sizeof() for string in C
- Difference between const char *p, char * const p and const char * const p
- Difference between %d and %i format specifier in C language
- Difference between float and double in C/C++
- Difference between fork() and exec()
- Difference between while(1) and while(0) in C language
- Difference between Header file and Library

