C Tutorial Part 3- Character Variables
C Tutorial Part 3-Character Variables
Hi, this is Cercomp and today I this post is going to be third in the C tutorial series. Last time, we discussed numeric variables. Today, we will be discussing character variables.
Character variables are the types of variables which are least used directly in c.
Mostly, they are used to create string variables using arrays, but that is still a bit advanced. A character variable is a type of variable which can store any one character(many characters together are stored by string variables). An example of a character can be anything, like r, t, v ,2. But now, after looking at the examples, you might argue that 2 can only be stored in a numeric variable. There is a difference between this 2 and that 2. This 2 can only be displayed as text. But that 2 can be operated(+,-,*,/) and also be displayed.
So now you might be thinking how to express this in code. Well, that is shown below!
1. First, you begin with the header and int main line.
2. Write char a;
a="p";
char is the syntax to create a character variable and a is the variable. But it can be anything you like. This is a function so it ends with a semicolon. In the line below, we have defined that the character variable a is equal to p. (p) is in inverted commas as it is a particular text character.
3. Now use the printf function and write-
printf ("The character is %c", a);
You know the printf function prints text in the inverted commas. The %c is the representation of the variable after the inverted commas, which is a.
4. Now save and compile the the program and run.
For any queries or donation, please visit -
https://cercomp.blogspot.com/p/cercomp-contact-info.html
https://cercomp.blogspot.com/p/cercomp-contact-info.html






Comments
Post a Comment