Consider the following C program.
int a = ‘d’;
/*OUTPUT – 100 (ASCII Code for character d)*/
int b = ‘dd’;
/*OUTPUT – 25700 (Explanation in detail given below)*/
We can easily guess that the output for ‘d’ is 100 as 100 is ASCII value of character ‘d’.
Let us consider below line
int a = 'dd'
(%d, a) prints 25700 as output
01100100 01100100 (Binary of 100 100)
Assuming int is of 2 bytes, starting byte is occupied by first character ‘d’ and second byte by second character ‘d’. Therefore overall binary involves 0110010001100100 i.e 2^14 + 2^13 + 2^10 + 2^6 + 2^5 + 2^2 = 25700.
Now guess the output of following code.
int b = ‘de’;
- Assigning an integer to float and comparison in C/C++
- Explicitly assigning port number to client in Socket
- Multiple Inheritance in C++
- Difference between while(1) and while(0) in C language
- Signals in C language
- Stopwatch using C language
- kbhit in C language
- fgets() and gets() in C language
- C Language Introduction
- Round to next greater multiple of 8
- Round to next smaller multiple of 8
- How to use POSIX semaphores in C language
- lvalue and rvalue in C language
- Which Programming Language to Choose?
- isalnum() function in C Language
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.