Course Content

Course Content

Basic Syntax

Hello everyone,

My name is …..and we are continuing with the C programming course.(7 seconds pause ; music)

In the previous videos, we had made our very first C program.

Yes, we had made our ‘Hello World program’ in which we had printed a sentence or statement named ‘Hello Word’ on the display or the screen.

In this video, we are going to see basic syntaxes of the C programming language.

okay! So, let’s begin…

Now, what is syntax?

Like in any other language for example, in English language, in English language to define the rules and regulations we have grammar.

Like if we have to make a sentence in the past tense then, we will make the use of the word “was” and that word “was” we will never use it in future tense.

If we use it then our English will be wrong.

In the same way, our C programming language or any other programming languages which are there, the way of writing them, that way of writing we call as syntax.

This is syntax which tells us how we have to write the things step by step,

in your program, where you have to define which things so that you acquire your desired output and you face no problem in that.

(01/37)

All these things are decided by our syntax and there are various components and parts in syntax which we will be discussing in this video.

So, without any delay, let's start and see the first thing; which is called tokens.

Now, first of all we will take an example, suppose we have to make a big building but the smallest thing that we will require to build this building.

Which means because of which our building will not be complete.

What is that? That will be one brick…

If we do not use bricks in our building, or we don't put the bricks in our building, the building will not be made.

As long as we don't align the bricks one upon the other and make a wall, till that time our building will not be started.

It will not be complete.

In the same way, our C program has small building blocks. It means like our main function was there in HelloWorld program or like in the printf statement or the preprocessor commands.

All these things were the building blocks because of which our C program was getting complete.

We call these tokens.

So, what are tokens, tokens are the building blocks of our C programme.

understood !

So, the C program consists of various tokens.

As the building blocks can be of different types, in the same way, our tokens can be also of different types and the characterization of the token has been done in these six types, which are visible on the screen.

The first type is of keywords, the first from the six are the ‘keywords’, then are the ‘identifiers’, then are ‘constants’, ‘strings’, ‘operators’ and ‘punctuators’.

Which we even call as special symbols.

So, we will see all these things one by one and understand what they exactly mean and what is their use.

The first thing that we are discussing or the first token that we are seeing, it's called identifiers.

We had discussed in our last video about a term which was called variables.

So, we had discussed, why are these variables called variables?

Because the values that we store inside it, like here in the example it is given, ‘num one is equal to three’.

So, the way to write is by using is equal to but, it actually means that our num one is one type of a variable or it is a variable itself and the value three that we are seeing on the right-hand side, that is going inside of a num one and it's getting stored.

So, basically when we say that we want num one, so the value inside num one, this three that we are storing inside it, we will get that.

In the same way, our variables.. and their values, they keep changing, so all these things, we have to customise as per the things that we have to get done in our program.

So, these variables, we make it ourselves.

(04/51)

As you saw here, this variable’s name was num one.

I could have named this variable anything like num two, num three or N U M underscore num, like this, I could have made any word and would have given to my variable this name.

The procedure of giving name to the variable and like we had read a few functions before like ‘printf function’ we had used in the ‘Hello World’ program.

These functions on variables, the name that we give them like here, we have given the name num one, this name is called as the identifier.

How am I able to identify this variable?

I'm able to identify This variable with its name, that is the reason why it is also called as identifiers.

So, these variables and functions or any other user defined items, u

ser defined items means any items that I am making myself,

they are not already made in the program, that means that in C program they are not made as it is,

the things that I am making or which I am programming, the names that we give to those things, we call those names as identifiers.

Like here in the examples, you can see there is num one, getchar (pronounce : get -ker), sum, abc, etc.

All these things are called identifiers.

The name that we are giving to these identifiers.

There must be some rules to give these names.

So, we will see the rules first, to give the name of the identifiers the rules that are there are as follows.

You can take any capital letters from A to Z. And even in small cases, you can use any character from small a to small z.

Apart from that, you can even use underscore to give name to your variable or to make it an identifier.

After that, our numerical values come like 0 to 9.

we can even include 0 to 9 characters while making our identifier’s name.

But, we have to keep in mind that our variables or identifier’s names should not start with the numerical value.

Like in this example, the name is num one, it is the correct name of an identifier and it is according to the rules.

If we make it one and after that num, this will be entirely wrong.

So, to write and make this identifier’s name, There are different rules that you can see here.

Apart from these characters, alphabets and numbers, there are other things in the English language like the special characters like hash, dot and hyphen.

So,we can not include all these things in the identifier's name.

(07/52)

You can only include capital A to Z, small a to z, underscore and apart from this, the numerical digits, that are the only things that we can use while making the names.

In that as well, there is one condition, that you will not start with numerical values and numerical digits.

You can use at the end or in the middle but your variables or identifier’s name should not start with it.

So, all these things we saw, what is the identifier and what are the ways to name it.

After that the second characterization of tokens… So, the first characterization of tokens we saw was identifiers.

Clear, so far?

The second is called as keywords, the program that we saw of hello world, in that we had to use few things like main and include So, these reserved names that we were seeing, these will be used in our every program and these are already reserved.

That means that whoever developed the C programming language, they reserved few of the fixed words and have given it a special meaning in our C program.

So that we cannot make identifiers of these names and these reserved words.

So, you must be able to understand this, that we make the name of the identifiers,

we made the variable so we gave it a name and that name was called as an identifier. but, these reserved words which were made in the C program, which had a specific reserved meaning, we cannot use these keyword’s names to make our identifier’s name.

“So, some reserved keywords names given in the next slide cannot be used as an identifier’s name”

okay!

So, we will see, which are those words, which have a reserved meaning, which are reserved and we cannot use them as identifier’s name.

Here. There are few words given like ‘auto, double, int , struct, break’ and there are many more in the list.

You can see it on your screen.

(10/00)

So, all these names which are there, basically they are called as key words.

And they are considered in tokens itself.

Bu,t we cannot make identifiers of these names.

Till now we have 2 things in tokens.

First were the identifiers and second were the keywords.

You cannot consider these key words and make the identifier’s name.

We have seen two things: identifiers and keywords.

After that, we'll go ahead and see what our strings are.

We had taken an example of the English language for grammar.

In this English language, when we are writing a few sentences, how do we say that our sentence is finished, we make use of a full stop.

This full stop tells our sentence, that this sentence has finished or another sentence will start after this.

In the same way, we had printed a Hello World statement on our screen in the Hello World program.

This string, we call it as string in the programming language.

So, this string that we had printed, this string has got over or this string is only this much, how will the compiler or the computer get to know this?

They get to know this with the help of a null character.

It means that you can see it in the fifth position. After HELLO, H E L L O, one character is written by joining 2 characters, this character is backslash and zero.

 With this character we get to know the sentence or the string has finished.

So, with this we can understand the letters or the sentences that we were printing on our screen, like we had made in the last program, the Hello World statement.

This Hello World was a string.

So, how will this string end, where will it end?

How will we know that, we will get to know that with this null character, which is represented by backslash and zero.

Are you getting it? good.

So, whenever in future, we will be making programs, we will display or store such sentences, this backslash and zero null character will get automatically added at the end of the sentences.

We will not be able to see it but behind the scenes, behind in the logic, it will be already defined and we will get to know, we mean the C compiler will get to know that this string is ending over here, after this, we don't have to consider the string.

If you don't use this null character then, what will happen?

(12/39)

The program that we have written before, will also be considered as string,

And even that, will be displayed.

And the special meaning of that string was being made before, special meaning of that will not be made.

That is the reason why this null character tells that this is the end of the string as the backslash and zero are very important to tell that our string has got over here.

So, till now, we have seen three things, first was identifier, second was keyword and the third thing that we saw was strings.

We will go ahead and see the fourth thing, the fourth characterization of tokens which are the operators.

Now, in mathematics, we have already used a lot of operators like plus, minus, multiplication, division.

So, all these arithmetical operations that we had used in mathematics, they are used as it is in the C language, it has a different characterization, which we call as operators.

Even these are tokens, since they are of a different type, the functionalities are different, that's the reason why we keep them in the section of operators.

Apart from these four arithmetic operators, there are many other operators which have a special meaning, like you can see in the example, apart from plus, minus, multiplication and division, going ahead with the examples are, double equal to, double plus, double minus has been given.

Its special meaning is reserved separately in the C programming language.

We will see their meaning with the program, when we will move further, but for this example , we will understand it, like we have written here a is equal to b plus c.

Here, is equal to has come only once, which means that assignment is used here, like in normal mathematics, we make use of this is equal to sine differently, we tell that these two things are equal, but how has it being used here?, you can see that b is also a variable, c is also a variable, which means that there are some values stored in them, these two are being added by using the plus sign and the addition of the values inside b plus c, where are we storing that, we are storing that in the third variable, which is called as a.

So, this equal to sign means to assign or to make an assignment.

So, the value that was coming from b plus c, that was getting assigned to ‘a’ variable.

In the same way, equal to has got a different meaning here in C programming language.

Apart from that, the double equal to, double plus and double minus have some extra or reserved meaning in our programming language which we will understand slowly moving ahead while making the programs.

So, for now, we have to understand that these operators are basically the tokens.

They are the building blocks of our C program.

We will go ahead and see the special characters used in our program.

(15/43)

What are these special characters?

When we made the Hello World program, a few characters were used.

Like you must have seen that round brackets and curly brackets were there.

For preprocessor command hash was being used, there was a semicolon used after the return zero statement.

So, all these special characters which are there, even these are a type of token and they have some reserved meaning.

Like you can see where these round brackets are used, we get to know that this is a function.

After that, the curly brackets tell us where our function is starting and where it is ending.

So, all these things have got a special meaning like you can see hash in this example.

Hash exactly means the ‘preprocessor directive’, which means our preprocessing commands that were there, which were telling us that you have to import this file or not.

The file importing command which was there, what was its starting?

It was with the hash symbol.

This hash symbol is also called a ‘preprocessor directive’.

As this is the starting point of the preprocessor command, these special characters have different meanings, few reserved meanings, in our C program.

when we will make programs on our own and practice them on our own.

We will prominently understand it’s meanings.

Till now, This was the fifth token from all the tokens that we have seen, after that the last token that comes is called as ‘constants’.

Constant in C,

we will understand it, this is a little different.

We had taken an example of variable, till now we all have understood that variable is a type of thing in which, we are able to store some value.

The value can be changed in the program whenever we want to change it.

That is the reason why we call it variable but, if I say that my program has such a requirement like for example, if I say pi which is constant in mathematics, which has a value of 3.14 or 22/7.

(18/00)

So, this value will always be constant, whatever multiplication or division you do. If you have to use the Pi value then, it will always be 3.14.

So, this I have to represent in my program and I want that in future, the line comes below which wants to change it.

It wants to change the value and make it 3.99 or any other value, the statement will now run properly or create some problem.

Means it’s value should be fixed and constant, it should not change.

I want to do something like this, so what I can do is, I can make it a constant,

means it is a variable, its value should change but since I have written c o n s t before of its name means I have made it a constant.

So, the first time whatever value is getting stored in it, even at the end of the program the same value will be stored, that value will not be changed.

Even if you want to change it, that value will not be changed and that will always be fixed.

 So, how can we make this particular variable a constant?

The way to do it, you can see it on the screen.

The’ abc’ that you're seeing is the name of the variable.

And what is the value stored in it? It is five.

In the middle, the int that you're seeing, you can ignore it for the meanwhile.

We will understand about it in our coming videos.

This is basically called a data type.

And what it means, we will know in the coming videos.

Now, you can safely ignore that.

 We have understood that abc is the name of the variable.

Five is a value which is getting stored in abc.

C O N S T in the start, it is making that variable constant, like if in abc you have earlier stored the value five, if going ahead in the program if you make the value to six or seven, then, value will not be changed.

Because I had put CONST before its name.

I have made it a constant that is a constant.

“So, a constant is a value assigned to the variable, which will remain the same throughout the program.”

Okay ! understood ?

Even till the end of the program, the value of that variable will remain constant.

So, we have seen all these things in tokens in which constants were there, special characters were there, identifiers were there, keywords were there, strings were there, operators were there.

So, we have seen all these things.

In the next video, we will see what data types are in the C programming language.

Like we have written in here int, but till now we have not understood the meaning of it, what is int doing here, what is its requirement?

So, this int is data type.

In the next video, we will understand what this int means.

How does it work? Till that time, thank you everyone.

If you have any queries or comments, click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.

Thank you so much.

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
Apple App Store
598K+ Downloads
App Download Section Circle 1
4.57 Avg. Ratings
App Download Section Circle 2
15K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere