Today we will learn variables , keywords and data-types in C , most important we will make out first C Program which is to print “Hello World!!!” .
So be ready with pen and paper and make proper notes so you can revise easily .
If you are not familiar to these don’t worry we will see one by one .
Print “Hello World!!!”
You are familiar with this code except 3rd line .
Line-3 : printf is a function and it is used to show output . Whatever you want to print write in printf with double quote .
Example:
printf(“Tick-Tick”) -> It will show Tick-Tick to the console/Output.
All functions are defined in particular header file . printf function is defined in “stdio.h” header file , So if you don’t include “stdio.h” it will give you error that printf function is not defined .
We will see more header files and their functions .
Assignment : Print your name .
you can try to print more things like .
“\n” is used to move cursor in new line , try yourself by using \n at different places and see the results .
Variables and Datatypes in C
Variable is the name given to a memory location . It store the value and we can modify value .
Since value can be your name, your age or any number so there are different-different datatypes which defines the types of variables . So let’s see datatypes used in C Programming -
- int : Store Numeric Value
- char : Store Character
- float : Store Floating value with single precision
- double : Store Floating value with double precision
So let’s see some variables -
- int a = 2;
- float b = 3.14;
- char c = ‘A’;
- double d = 22.12;
Keywords in C
Keywords are reserved words that you can’t use in your program for any other purpose because they are defined for specific purpose .
There are total 32 keywords in C .
Here is a list of Keywords -
- auto
- break
- case
- char
- const
- continue
- default
- do
- double
- else
- enum
- extern
- float
- for
- goto
- if
- int
- long
- register
- return
- short
- signed
- sizeof
- static
- struct
- switch
- typedef
- union
- unsigned
- void
- volatile
- while
Print Variables
Previously we have printed Hello World!!!, name etc.
we use special format specifiers to print variables which starts with % and then type of variables .
Here are format specifiers -
- int : %d
- float : %f
- char : %c;
- double : %lf
- long : %ld
- long long : %lld
- long double : %Lf
- octal : %o
- hexadecimal : %x
- unsigned int : %u
printf(“c =%c\nf = %f”,c,f); first %c will be replaced by value of c and second %f will be replaced by the value of variable f.
If you find the content of this website interesting and helpful, use the “Buy HW Programmer a Coffee” link below to buy me a coffee. Your generosity will keep me caffeinated and Inspire me to keep the website up and running .
Thank you so much for your consideration.
https://ko-fi.com/hwprogrammer
Let’s Connect with us :
Instagram : https://www.instagram.com/hwprogrammer/
Facebook Page : https://www.facebook.com/hwcoder
Facebook Group : https://www.facebook.com/groups/838100380386300