previous sessions:
we already have taken printf function and we knew that it is used for printing anything on the screen.
This session :
we are going to learn the following :
- practice on printf function
- \n ,\b, \a and \t
- variables
Practice 1
write a program that prints your name and age on the screen.
\n ,\b, \a and \t
\n used when we want to print something in a separate line.
\b used when we want to make a backspace.
\a used when we want to make an alert.
\t used when we want to make a tab space.
modify the previous program to print your name and age each in separated lines, so your code would be like this:
#include<stdio.h>
int main()
{
printf("my name is xyz\n my age is xyz\n");
return 0;
}
compile and run
Now modify your program by replacing \n with \t and see the difference.
- gcc se2.c -o se2.out - Press Enter
- ./se2.out - Press Enter
My name is xzy my age is xyz
Then modify your program by adding\a with \t and see the difference.
your output should look like this:
#include<stdio.h>
int main()
#include<stdio.h>
int main()
{
printf("my name is xyz\t my age is xyz\a");
return 0;
}
Variables
what
does that mean?
when
you need a space in memory for doing something you ask for a variable.
As you can see a variable is a place in memory where we can store
data and this data could be replaced any time we want.
What type of data can be stored in this place?Well you can store data only in places that can hold.
If the previous place can hold only one piece of this data can we
put two inside it?
Sure no as we need a bigger place so it can hold more pieces from
this kind of data as we see in the next picture.
No comments:
Post a Comment