00
in this session let's see another simple
0:05
program and try to study what is going
0:08
ok so here i have a slightly more
0:14
complicated program than what we just
0:15
saw this last 22 printf statement one
0:23
says welcome to and the second says c
0:26
programming to slightly more
0:28
sophisticated than the code that we have
0:31
seen so to recap the first line hash
0:35
include a studio dot it tells the
0:38
compiler to include the standard output
0:40
library then we have the main function
0:46
the open and close brackets immediately
0:50
after main show that main is a function
0:53
execution always begins at the first
0:57
line of the main statement then the body
1:01
of the function the logic of the
1:02
function is enclosed within two curly
1:04
braces the first curly brace signals the
1:08
beginning of the function and the last
1:11
curly braces that the function is over
1:13
here this particular main function has
1:20
two statements or later we had just one
1:21
statement the each statement as i said
1:25
before is terminated with a semicolon
1:29
so this is the first semicolon and this
1:36
is the second semicolon the first
1:39
semicolon says that the statement print
1:42
of welcome to ends at that point and
1:45
then followed by the second statement
1:47
and the second statement is also
1:49
dominated by a semicolon every statement
1:52
in c is terminated with a semicolon
1:55
curly braces in close a set of statement
1:59
and the each statement in a sequence is
2:03
executed in the exact sequence that we
2:07
now once we did this in a native save
2:12
the fight now compile and run the file
2:15
so let's call it sampled see or you may
2:18
rename it in any file you want and then
2:21
once the compilation is successful you
2:24
can run it using dot /a doubt and then
2:29
it will print they'll come to c
2:31
programming which was essentially the
2:33
same message as we've seen before
2:35
let's trace what happens when the
2:41
execute the program by tracing the mean
2:43
step-by-step looking at each statement
2:46
and sees see what happens when the
2:49
program executes ok you have what is
2:54
known as a program counter which says
2:56
here is the currently executing line of
2:59
program the program counter starts
3:02
executing at the first statement of me
3:04
for ease of reference i have given line
3:09
numbers in the code now this is given
3:13
just for crafting now let's just see
3:16
what happens when we run the program
3:19
ok so first the execute the first line
3:25
of the code after we are done executing
3:28
that line for so after we had done
3:30
executing lines 3 and 4 the message
3:34
welcome to will be printed on the
3:36
permanent this will be followed by the
3:39
next line so the next line says C
3:44
ok so after the lengths line execute it
3:48
will print c programming percentage I've
3:51
given this in two different colors to
3:53
highlight that one was printed by the
3:56
first line and the other was printed by
3:57
the second time otherwise the colors
3:59
have no say no special meaning the
4:03
program terminates when the main
4:05
finishes execution and this is what is
4:09
typically known as returning from the
4:12
function we will see this terminology
4:19
in addition to the statements which are
4:24
you may also give a few additional
4:27
these are water notice from program
4:30
comments for example the lines a simple
4:34
C program first print and second print
4:37
these other comments in the code
4:39
ok so whatever is highlighted in red in
4:42
the code is what are known as comments
4:44
any texts between forward slash start
4:48
and then later followed by a start
4:52
/so any texts between successive / star
4:56
and star slash is a comment and it will
5:00
be ignored by the compiler so the as far
5:02
as the compiler is concerned a chord
5:04
with comments is the same as a code
5:06
without comments it doesn't affect the
5:09
logic of the code so comments are not
5:12
part of the program however it is highly
5:14
recommended that any program you're
5:17
right you should come in the code
5:19
ok this is so that other people can
5:21
understand your code also you yourself
5:25
looking at the code for months later or
5:28
five months later it is it may be
5:31
difficult to understand what you wrote
5:33
much before and commands help you
5:36
understand the logic of the program now
5:40
it is a very good idea to come into your
5:42
programs and for larger programs
5:45
it is a must to come in the program's
5:47
this is standard industry practice and
5:51
even if you are participating in large
5:52
programming projects like free software
5:55
projects comments that highly increase
5:58
because it will understand other
6:00
developers that programmers to
6:03
understand your code
6:04
ok so we will try to follow our own
6:08
most of the programs that we will see in
6:09
this code I be able to comment it so
6:12
that it's easy to follow the logic of
6:14
the cord now a few notes just as main is
6:20
a function printf is also a function or
6:24
interface at library function which
6:27
it is given by the C programming
6:29
language and we wanted to tell the
6:33
compiler to include this library
6:36
function the statement said that is this
6:38
hash include stdio dotted so hash
6:41
include the studio tortoise edline
6:43
telling that i want the standard
6:47
input/output library because that is the
6:49
library from which i would get the
6:51
function printed now what what does
6:55
Princess do print of takes two arguments
6:58
just like arguments to mathematical
7:01
functions so it takes an input argument
7:03
within our first case was welcome to so
7:07
this was the print of first point of
7:09
statement of their program that we just
7:11
saw now this was enclosed in double
7:17
quotes right so it was enclosed in an
7:21
open double coat and then ended with a
7:24
close double quote a sequence of
7:26
characters in double quotes is what is
7:28
known as a string constant now we can
7:33
call the functions that we define or we
7:37
can call the functions that the
7:39
libraries provide ok this is how once
7:42
you define a function you can call a
7:44
function now we'll see an additional
7:50
concept the printf statements that we
7:53
have seen so far we will print a message
7:55
and it will print there and then the
7:58
prompt the terminal prompt will come
8:01
immediately after the print you know
8:03
typically what we want to do is we'll
8:05
print a message then say that tells the
8:08
prompt appear on the next line
8:10
ok so for this we need what is known as
8:13
the newline character all letters digits
8:17
comma punctuation symbols
8:20
these are all called characters in the c
8:22
programming language there are a total
8:24
of 256 characters and see 256 is 2 to
8:29
the 8 so for example the small letters a
8:33
to Zed capital letters a tues it 029
8:38
the symbol other punctuation symbols
8:40
like dot comma ! and so on our own
8:46
characters and see now in addition to
8:50
this there are certain things
8:51
concessional characters so there is a
8:54
special character called new line in the
8:57
C programming language it is denoted as
8:59
backslash and ok so there are notice
9:03
that there are two kinds of slashes /in
9:05
backward slash on your keyboard and the
9:08
newline character is denoted as
9:10
backslash and so even though it is a
9:15
single character it is denoted by two
9:17
directors been used in print if it
9:20
causes the current output line to end
9:22
and then printing will start from the
9:27
ok so it is something which says the
9:29
current line has ended now whatever you
9:31
have to print print it on the next time
9:33
the newline character backslash in is
9:37
like any other later and can be used
9:39
multiple times in any particular line
9:43
okay for example if you have something
9:48
to print followed by back session
9:51
followed by C followed by something to
9:54
print now this will be treated as so
9:57
many characters and then a new line
10:00
ok so let's see a particular example if
10:03
you have the old program that we just
10:07
wrote but we end each message with a
10:10
backslash in ok so we have printed
10:12
welcome to vaccination printf c
10:16
programming back session
10:18
ok when we compile and execute will see
10:22
ok so when we run this as dot slash a
10:26
doubt it will print welcome to and then
10:30
the next thing to print is is a back
10:32
selection which is a new line so
10:34
printing will start from the next line
10:36
and then it will print the next message
10:40
which is c programming so it will print
10:43
that followed by a new line so the
10:46
prompt will appear on the line
10:50
so a newline character is something that
10:52
is used to make your output messages a
10:57
little more right here so let's just
11:02
conclude by saying one more thing about
11:04
new lines the newline character
11:07
exploration is like any other character
11:09
and you can use it multiple times even
11:12
within a single message for example if i
11:15
do the same program but let's say say I
11:20
welcome to vaccination backslash in
11:24
ok so i have repeated occurrences of
11:27
vaccination in the same message what it
11:29
will do is it will print the message
11:31
welcome to then it will print a new line
11:34
and then it will print and a deadline
11:37
and then interpret see followed by a new
11:40
ok so when you run the program you would
11:42
have welcomed to new line then the blank
11:45
line then C and then another length
11:47
ok so new lines had just like any other
11:50
the difference is that because it's a
11:52
special character it is represented by
11:54
two letters so it is not represented by
11:57
a single letter it is represented by
12:00
backslash and so they are together one
12:04
character in c called the newline
No comments:
Post a Comment