You are on page 1of 3

CLASS 02 GUIDE 

 
In this class, we are going to cover the following topics: 
 
● Comments  
● Data types 
● Variables 
● Data assigning to variables 
● Placeholders 
 
COMMENTS​: 
Comments are always ignored by C. They are used for your convenience; in case you need to write a 
note that what a piece of code does. 
There are 2 types of comments: Single-Line Comments & Multi-line comments. 
 
Single-Line Comments -​ ​As the name suggests, Single-line comments can only be written on one 
line. If you press enter and write your comments on the next line, it won’t work. To write a single 
line comment just type double forward slashes → ​// 
 
Example:  
// This is a single line comment 
 
Multi-Line Comments -​ ​As the name suggests, multi-line comments can be written using multiple 
lines. That is if you press enter in the middle of a line C won’t complain. 
The syntax is ​/* Your comment goes here */ 
 
Example:  
/* 
This is  
a multi-line 
Comment */ 
 
DATA TYPES​: 
Data Types are basically types of data- as simple as that. For example, number, strings, characters, 
etc. 
 
The ​number ​data type can be categorized into two more parts: integers and decimal point values. 
● Integers are those numbers who don’t have a decimal value like 8, 9, 1000, -8, 6755, etc. 
● Decimal points are just the opposite: numbers with decimal points like 8.0, 6.7, 1000.90, 
-92.4, 67.6666, etc. 
The ​character ​data type specifies a single character. For example c, 8, u, A, etc. 
 
 
How do we tell C about all these data types? 
 
They have a special syntax for that.  
 
To specify an integer value, we use the ​int ​keyword. 
To specify a decimal point value we use the ​double ​keyword. 
To specify a character value we use the ​char ​keyword. 
 
These are reserved keywords that C will understand automatically. 
 
VARIABLES​: 
A variable holds value for you. It’s just like a storage box. It will store a value for you. 
We use variables to store data of different data types. 
For example, a variable can hold an integer. 
 
How to declare a variable? 
 
The syntax goes like this, you mention the data type first (which you select from above: int double 
char) then you mention the name of the variable (the name can be anything you want) and end with 
a semi-colon: 
 
datatype​ ​variableName​; 
For example, 
int​ ​potato​; 
char​ ​fajita​; 
double​ ​chicken​; 
IMPORTANT NOTE: Variable names cannot have spaces in between them. You can either use 
camelCase or use underscore like this: camel_case Variables should not contain punctuations 
except underscore. Variable names should always be unique i.e you cannot have two variables 
with the same name. A variable name should not ​start ​with numbers or any punctuations 
except underscore. 
 
For example, 
int​ ​chickenSalad​; → camel Case method 
char​ ​kacchi_biriyani​; → using underscore method 
double ​_​faluda​; → names starting with underscore 
 
ASSIGNING DATA TO VARIABLES​: 
The main purpose of the variable is holding data. This topic explains how you can tell a variable to 
hold data. You assign a value to a variable using the ​=​ ​sign. 
For Example: 
int​ ​banana ​=​ ​9​; 
double ​banana ​=​ ​10.78​; 
For char variables assigning is a bit different. It goes like this → it should be enclosed within a 
single quote. 
char ​apple ​=​ ​‘​c​’; 
RE-ASSIGNING DATA TO VARIABLES​: 
You can change the value of a variable after you have assigned it or declared it. 
 
Example 01: Declaring variable first and assigning a value later. 
int​ ​starKabab​; 
starKabab​ =​ 19; 
Example 02: Declaring a variable and assigning value at the same time.  
int​ ​takeOut ​= ​57​; 
Example 03: Declaring a variable, assigning a value and changing it later  
double ​madChef ​= ​59.6​; 
madChef ​= ​98.10; 
 
PLACEHOLDERS​: 
Placeholders are used to print the variable’s data.  
Different data types have different placeholders: 
● int → %d 
● double → %lf 
● char → %c 
 
For example, if you want to print the value of ​takeOut​ variable declared above you would do the 
following: 
printf(“This is %d”, takeOut); 
Example 02: 
printf(“Mad Chef has the value %lf”, madChef); 
 
Try out ​%c​ for yourself. 
--------------------------------------------------------------------------------------------------------------------------------------------------------- 
 

You might also like