×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

Character (char) - find output of C programs

Find output of C programs (char data type) in C: Here, you will find some of the C programs based on character (char) with the outputs and explanations.

Program-1

#include <stdio.h>

int main()
{
	char ch='A';
	printf("%d",ch);
	return 0;
}

Output

65

Explanation

Here, value of "ch" is 'A' and we are printing the value "ch" in integer format (using "%d" format specifier). Thus, the output will be 65 (which is the ASCII code uppercase character 'A').


Program-2

#include <stdio.h>

int main()
{
	char ch='A';
	printf("%c-%d",ch+32,ch+32);
	return 0;
}

Output

a-97

Explanation

Variable contains ASCII code of 'A' which is 65. And we are printing "ch+32" which will be 97 and the format specifier "%c" will print "a" and "%d" will print 97.


Program-3

#include <stdio.h>

int main()
{
	int a= 'a'-'A';
	printf("%d[%c]",a,a);
	return 0;
}

Output

32[ ]

Explanation

ASCII code of 'A" is 97 and ASCII code of 'A' is 65, difference of 'a' and 'A' is 32, and 32 is the ASCII code of space. Thus, the output of this program is 32[ ].


Program-4

#include <stdio.h>

int main()
{
	char ch='g';
	printf("%c",ch-('a'-'A'));
	return 0;
}

Output

G

Explanation

'a' - 'A' will return 32, ch contains the ASCII code of 'g' which is 103 and the result of the statement ch-('a'-'A') will be 71. Thus, the output of the program is 'G' which is the character of ASCII code 71.


Program-5

#include <stdio.h>

int main()
{
	printf("%d",('1'-48));
	return 0;
}

Output

1

Explanation

Here '1' is not an integer value; it's a character and its ASCII code of 49. Thus, the result of the statement ('1'-48) will be 1.





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.