Introduction to
Programming
 Programming is writing computer code to create a
program, to solve a problem. Programs are
created to implement algorithms. Algorithms can
be represented as pseudo code or a flowchart,
and programming is the translation of these into a
computer program.
 To tell a computer to do something, a program
must be written to tell it exactly what to do and how
to do it. If an algorithm has been designed, the
computer program will follow this algorithm, step-
by-step, which will tell the computer exactly what it
should do.
Programming Language
A programming language is an
artificial language that a computer
understands. The language is made up
of series of statements that fit together
to form instructions. These instructions
tell a computer what to do.
Categories of Languages
Each programming language contains a unique
set of keywords and syntax, which are used to
create a set of instructions. Thousands of
programming languages have been developed
till now, but each language has its specific
purpose. These languages vary in the level of
abstraction they provide from the hardware.
Some programming languages provide less or
no abstraction while some provide higher
abstraction. Based on the levels of abstraction,
they can be classified into two categories:
 Low-level language
 High-level language
Low Level Language
The low-level language is a programming
language that provides no abstraction
from the hardware, and it is represented
in 0 or 1 forms, which are the machine
instructions. The languages that come
under this category are the Machine
level language and Assembly language.
Machine-level language
The machine-level language is a language
that consists of a set of instructions that
are in the binary form 0 or 1. As we
know that computers can understand
only machine instructions, which are in
binary digits, i.e., 0 and 1, so the
instructions given to the computer can
be only in binary codes.
Assembly Language
The assembly language contains some
human-readable commands such as mov,
add, sub, etc. The problems which we were
facing in machine-level language are
reduced to some extent by using an
extended form of machine-level language
known as assembly language. Since
assembly language instructions are written
in English words like mov, add, sub, so it is
easier to write and understand.
Ex. ADD(2,4)
Assembler
As we know that computers can only
understand the machine-level
instructions, so we require a translator
that converts the assembly code into
machine code. The translator used for
translating the code is known as an
assembler.
High-Level Language
The high-level language is a programming
language that allows a programmer to
write the programs which are
independent of a particular type of
computer. The high-level languages are
considered as high-level because they
are closer to human languages than
machine-level languages.
History of C Language
 History of C language is interesting to
know. Here we are going to discuss a brief
history of the c language.
 C programming language was developed
in 1972 by Dennis Ritchie at bell laboratories
of AT&T (American Telephone & Telegraph),
located in the U.S.A.
 Dennis Ritchie is known as the founder of
the c language.
 It was developed to overcome the problems
of previous languages such as B, BCPL, etc.
Features of C Language
Structure of a C Program
First C Program
 #include <stdio.h>
 int main()
 {
 printf("Hello C Language");
 return 0;
 }
Elements of C
Execution Characters/Escape
Sequences
Tokens in C
Keywords in C
Keywords in C can be defined as the pre-
defined or the reserved words having
its own importance, and each keyword
has its own functionality. Since
keywords are the pre-defined words
used by the compiler, so they cannot be
used as the variable names.
Identifiers in C
Identifiers in C are used for naming variables, functions, arrays,
structures, etc. Identifiers in C are the user-defined words. It can be
composed of uppercase letters, lowercase letters, underscore, or digits,
but the starting letter should be either an underscore or an alphabet.
Identifiers cannot be used as keywords. Rules for constructing
identifiers in C are given below:
 The first character of an identifier should be either an alphabet or an
underscore, and then it can be followed by any of the character, digit,
or underscore.
 It should not begin with any numerical digit.
 In identifiers, both uppercase and lowercase letters are distinct.
Therefore, we can say that identifiers are case sensitive.
 Commas or blank spaces cannot be specified within an identifier.
 Keywords cannot be represented as an identifier.
 The length of the identifiers should not be more than 31 characters.
 Identifiers should be written in such a way that it is meaningful, short,
and easy to read.
Strings in C
String are always represented as an array of
characters having null character '0' at the
end of the string. This null character
denotes the end of the string. Strings in C
are enclosed within double quotes, while
characters are enclosed within single
characters. The size of a string is a number
of characters that the string contains.
Now, we describe the strings in different
ways:
char a[10] = "javatpoint"; // The compiler
allocates the 10 bytes to the 'a' array.
Constants in C
A constant is a value assigned to the
variable which will remain the same
throughout the program, i.e., the
constant value cannot be changed.
There are two ways of declaring constant:
 Using const keyword
 Using #define pre-processor
Special characters in C
Some special characters are used in C, and they have a special meaning
which cannot be used for another purpose.
 Square brackets [ ]: The opening and closing brackets represent the
single and multidimensional subscripts.
 Simple brackets ( ): It is used in function declaration and function
calling. For example, printf() is a pre-defined function.
 Curly braces { }: It is used in the opening and closing of the code. It is
used in the opening and closing of the loops.
 Comma (,): It is used for separating for more than one statement and
for example, separating function parameters in a function call,
separating the variable when printing the value of more than one
variable using a single printf statement.
 Hash/pre-processor (#): It is used for pre-processor directive. It
basically denotes that we are using the header file.
 Asterisk (*): This symbol is used to represent pointers and also used
as an operator for multiplication.
 Tilde (~): It is used as a destructor to free memory.
 Period (.): It is used to access a member of a structure or a union.
Variables in C
 A variable is a name of the memory
location. It is used to store data. Its
value can be changed, and it can be
reused many times.
 It is a way to represent memory location
through symbol so that it can be easily
identified.
 Let's see the syntax to declare a
variable:
 type variable_list;
 int a=10,b=20;//declaring 2 variable of intege
r type
 float f=20.8;
 char c='A';
Types of Variables in C
 There are many types of variables in c:
 local variable
 global variable
 static variable
 automatic variable
 external variable
cunit1.pptx
cunit1.pptx
cunit1.pptx
cunit1.pptx

cunit1.pptx

  • 2.
    Introduction to Programming  Programmingis writing computer code to create a program, to solve a problem. Programs are created to implement algorithms. Algorithms can be represented as pseudo code or a flowchart, and programming is the translation of these into a computer program.  To tell a computer to do something, a program must be written to tell it exactly what to do and how to do it. If an algorithm has been designed, the computer program will follow this algorithm, step- by-step, which will tell the computer exactly what it should do.
  • 3.
    Programming Language A programminglanguage is an artificial language that a computer understands. The language is made up of series of statements that fit together to form instructions. These instructions tell a computer what to do.
  • 4.
    Categories of Languages Eachprogramming language contains a unique set of keywords and syntax, which are used to create a set of instructions. Thousands of programming languages have been developed till now, but each language has its specific purpose. These languages vary in the level of abstraction they provide from the hardware. Some programming languages provide less or no abstraction while some provide higher abstraction. Based on the levels of abstraction, they can be classified into two categories:  Low-level language  High-level language
  • 5.
    Low Level Language Thelow-level language is a programming language that provides no abstraction from the hardware, and it is represented in 0 or 1 forms, which are the machine instructions. The languages that come under this category are the Machine level language and Assembly language.
  • 6.
    Machine-level language The machine-levellanguage is a language that consists of a set of instructions that are in the binary form 0 or 1. As we know that computers can understand only machine instructions, which are in binary digits, i.e., 0 and 1, so the instructions given to the computer can be only in binary codes.
  • 7.
    Assembly Language The assemblylanguage contains some human-readable commands such as mov, add, sub, etc. The problems which we were facing in machine-level language are reduced to some extent by using an extended form of machine-level language known as assembly language. Since assembly language instructions are written in English words like mov, add, sub, so it is easier to write and understand. Ex. ADD(2,4)
  • 8.
    Assembler As we knowthat computers can only understand the machine-level instructions, so we require a translator that converts the assembly code into machine code. The translator used for translating the code is known as an assembler.
  • 10.
    High-Level Language The high-levellanguage is a programming language that allows a programmer to write the programs which are independent of a particular type of computer. The high-level languages are considered as high-level because they are closer to human languages than machine-level languages.
  • 13.
    History of CLanguage  History of C language is interesting to know. Here we are going to discuss a brief history of the c language.  C programming language was developed in 1972 by Dennis Ritchie at bell laboratories of AT&T (American Telephone & Telegraph), located in the U.S.A.  Dennis Ritchie is known as the founder of the c language.  It was developed to overcome the problems of previous languages such as B, BCPL, etc.
  • 15.
    Features of CLanguage
  • 16.
    Structure of aC Program
  • 17.
    First C Program #include <stdio.h>  int main()  {  printf("Hello C Language");  return 0;  }
  • 18.
  • 19.
  • 20.
  • 21.
    Keywords in C Keywordsin C can be defined as the pre- defined or the reserved words having its own importance, and each keyword has its own functionality. Since keywords are the pre-defined words used by the compiler, so they cannot be used as the variable names.
  • 23.
    Identifiers in C Identifiersin C are used for naming variables, functions, arrays, structures, etc. Identifiers in C are the user-defined words. It can be composed of uppercase letters, lowercase letters, underscore, or digits, but the starting letter should be either an underscore or an alphabet. Identifiers cannot be used as keywords. Rules for constructing identifiers in C are given below:  The first character of an identifier should be either an alphabet or an underscore, and then it can be followed by any of the character, digit, or underscore.  It should not begin with any numerical digit.  In identifiers, both uppercase and lowercase letters are distinct. Therefore, we can say that identifiers are case sensitive.  Commas or blank spaces cannot be specified within an identifier.  Keywords cannot be represented as an identifier.  The length of the identifiers should not be more than 31 characters.  Identifiers should be written in such a way that it is meaningful, short, and easy to read.
  • 24.
    Strings in C Stringare always represented as an array of characters having null character '0' at the end of the string. This null character denotes the end of the string. Strings in C are enclosed within double quotes, while characters are enclosed within single characters. The size of a string is a number of characters that the string contains. Now, we describe the strings in different ways: char a[10] = "javatpoint"; // The compiler allocates the 10 bytes to the 'a' array.
  • 25.
    Constants in C Aconstant is a value assigned to the variable which will remain the same throughout the program, i.e., the constant value cannot be changed. There are two ways of declaring constant:  Using const keyword  Using #define pre-processor
  • 27.
    Special characters inC Some special characters are used in C, and they have a special meaning which cannot be used for another purpose.  Square brackets [ ]: The opening and closing brackets represent the single and multidimensional subscripts.  Simple brackets ( ): It is used in function declaration and function calling. For example, printf() is a pre-defined function.  Curly braces { }: It is used in the opening and closing of the code. It is used in the opening and closing of the loops.  Comma (,): It is used for separating for more than one statement and for example, separating function parameters in a function call, separating the variable when printing the value of more than one variable using a single printf statement.  Hash/pre-processor (#): It is used for pre-processor directive. It basically denotes that we are using the header file.  Asterisk (*): This symbol is used to represent pointers and also used as an operator for multiplication.  Tilde (~): It is used as a destructor to free memory.  Period (.): It is used to access a member of a structure or a union.
  • 28.
    Variables in C A variable is a name of the memory location. It is used to store data. Its value can be changed, and it can be reused many times.  It is a way to represent memory location through symbol so that it can be easily identified.  Let's see the syntax to declare a variable:  type variable_list;
  • 29.
     int a=10,b=20;//declaring2 variable of intege r type  float f=20.8;  char c='A';
  • 30.
    Types of Variablesin C  There are many types of variables in c:  local variable  global variable  static variable  automatic variable  external variable

Editor's Notes

  • #18 #include <stdio.h> includes the standard input output library functions. The printf() function is defined in stdio.h . int main() The main() function is the entry point of every program in c language. printf() The printf() function is used to print data on the console. return 0 The return 0 statement, returns execution status to the OS. The 0 value is used for successful execution and 1 for unsuccessful execution.