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
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
08 May, 2017
Like Article
Save Article