Lesson 2 - 7/Nov/2015

Hello friends, it's our second day and as we do not have any practical we will continue with the theory part.

Now, before we start with C Programming, we should know some history of C Programming Language.

History of C Language

As we know C is not the only language present in the market. There are many other languages present in the market and even before C there were many languages. The predecessors of C were B and BCPL, which were chosen as base for C. With the base of B and BCPL Dennis Ritchie invented C in 1972 at AT&T's Bell Laboratories, assisted by Brian Kernighan.

Before invention of C, there were few languages leading the market like FORTRAN, COBOL, PASCAL, ALGOL and PL/I. Most of these languages are still used(FORTRAN, COBOL and PASCAL are still used in IBM Mainframes). In 1973 when Dennis Ritchie wrote UNIX in C and looking at the easiness provided by the language, it started becoming popular. With the increasing popularity of C, vendors started writing their own definitions of C Language. This lead to the variety of flavors of C. In around 1980's C language became the most trustworthy language for writing the applications and replaced most of the popular languages at that time.

Looking at the increasing popularity of the C Language, ANSI(American National Standards Organization) decided to form a committee to make a standard for C Language. This committee came up with a first draft of Standards for C in 1989 which is known as ANSI C89 and later in 1999 they created another amendment and that is known as ANSI C99.

That's enough of history now... Let's have a look at some basics of C Language.

C Language Basics

To learn any language we need to understand the basics first. Let's take an example of English.

To learn English language we first have to learn the Alphabets and Digits of the language along with the Symbols. Then we create some words with the alphabets. After that we form some statements by combining few words with some grammar. A few statements together will form a paragraph and a set of paragraphs will make a page. With few pages we can create a book.

Now that was about English and let's discuss about C. To learn C Language or probably any programming language we need to understand the Character Set of the language, few terms that will be used in programming and Structure of Program in a particular Language.

So let us now try to understand C Basics.

Let us learn about some new terminologies that we will use throughout the course.

Variable
Constant
Keyword

and there are many more terms that will be introduced to you during the course. But for now, we will concentrate on these 3 terms.

Character Set of C :- Every programming language has a predefined set of Character Set. C uses the following Character Set.

Alphabets :- a-z, A-Z
Digits :- 0-9
Symbols :- . , < > ? / ; : ' " ~ ! @ # % ^ & * ( ) _ - + = { } [ ] \ |and many other symbols.

Variable :- An entity that may change in its value as per time and/or requirement.

For example, temperature is a variable. At different time in a day, temperature is different(Morning, Afternoon, Evening and Night). Also in an office or at home we can change room temperature by using AC Remote as per our requirement. That means the value of the parameter 'temperature' can vary according to time or requirement.

Constant :- An entity that never changes in its value at any point in time.

For example, the value that is placed in the variable is Constant. Temperature value 23.4 C. Let us try to understand this in brief. Values of two variables can be same, like temperature of two rooms can be same. However, values of two constants can  not be same. For example, 10 can not be equal to 100.

Constant have their own values or meaning and those values or meanings can not be changed by anyone. Alphabets have their own meanings and that can not be changed. For example, a name Rahul can not be written with 'D' as the first letter of it.

Keyword :- These are the special words with special meaning that are already known to the Compiler.

For example, 'if', 'while', 'void', 'int' and many more keywords are provided to us by C Library so as to make us enable of writing strong programs.

Keywords can not be used as variables or values of variables or identifiers. C language provides a set of 32 keywords.

Now, we will discuss about some rules of C Language.

Rules for writing Variable Names

1. Variable name must start with an alphabet (a-z or A-Z) or an underscore(_).
2. Variable name can be any combination of alphabets and digits.
3. No special symbol other than _ (underscore) is allowed in variable name.
4. Variable name must not start with a digit.
5. White spaces are not allowed in variable name i.e. single space, tab space or new line.

Here are few examples of good variable names and bad variable names

Good Variable Names

a. nameOfPerson
b. salary_of_employee
c. subject1, subject2
d. _myVar
e. version_1_update_2_1

Bad Variable Names

a. name of person - (spaces not allowed)
b. salary-of-employee (no special symbols allowed)
c. 1subject, 2subject (must start with alphabet not digit)
d. ver_1_upd_2.1 (no special symbol other than (_) underscore)

Generally try to avoid variable names beginning with underscore(_) as variable names preceded with _ are generally system variable.

Now, when we will write our programs we will need to store data in our program. This data will be stored in the variables in many different forms or types.

In our day to day life we deal with different types of data like numeric and alphabetic data. We deal with different types of numbers like whole numbers, fractional numbers, rational and irrational numbers and still many more types. Apart from these various types we have many other types of data to work with.

So we need to handle a lot of data in programs too. And just for the sake of that we need to understand Data Types.

Data Types

What are data types? Data type is nothing but various forms of data we are dealing with while writing programs. This data needs to be of specific type and should have some specific characteristics. These are defined by the Data Types. 

What data types we have and what are their characteristics?

There are two basic categories of Data Types.
Primitive Data Types and Derived Data Types.

That's all for today. We will see the data types in next session. So see you on Monday with another set of Theory Session.

Happy Coding!!!

No comments:

Post a Comment