Tuesday, April 16, 2024
HomejQueryC++ char Information Sort

C++ char Information Sort


Declaring and displaying char sort variables in C++



Output:

CPP-char

C++ char knowledge sort briefly

  • The char is a knowledge sort in C++
  • It’s used to retailer a single character
  • The character should be enclosed in a single quote e.g. ‘a’, ‘b’, ‘5’
  • The char sort takes one byte (8 bits) within the reminiscence
  • The worth of char is saved as an integer within the reminiscence
  • You might also assign ASCII values to the char sort (See instance within the part beneath)
  • Although it will depend on the compiler, the utmost worth {that a} char sort can retailer is often 255.

Assigning ASCII code worth to char sort

Within the following instance, we assigned ASCII values to the three char-type variables. Then we displayed their values:



 

Output:

CPP-char-ascii

You noticed as we assign a price with no single quote, it’s taken as an ASCII worth. As we displayed the variable, it show the corresponding worth to the ASCII character.

Checking reminiscence measurement of char sort

By utilizing sizeof() perform, you might test the scale of a variable. The C++ program beneath shows the scale of char sort variables:



Output:

CPP-char-size

You noticed the scale is displayed as 1. Which means, one byte of reminiscence taken by the char sort variable

Getting the best worth a char sort can retailer

The instance beneath exhibits the utmost worth a char sort can retailer:



Output:

CPP-char-max

Get the ASCII worth of Consumer entered character

Within the following program, the person is requested to enter a personality. We’ll then show the ASCII worth of that character:



Pattern Output 1:

Pattern Output 1:

CPP-char-get-ASCII

Pattern Output 1:

CPP-char-get-ASCII


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments