0% found this document useful (0 votes)
24 views

02-Introduction C Topic-01

A computer program is a list of instructions that tells the computer what to do. Programming languages allow programmers to write these instructions in a structured language. The first program ever written will print "Hello World" to the screen using C, a widely used programming language. It includes comments to document the code, standard input/output libraries, and returns 0 to indicate the program completed successfully.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

02-Introduction C Topic-01

A computer program is a list of instructions that tells the computer what to do. Programming languages allow programmers to write these instructions in a structured language. The first program ever written will print "Hello World" to the screen using C, a widely used programming language. It includes comments to document the code, standard input/output libraries, and returns 0 to indicate the program completed successfully.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

Introduction

WHAT IS A PROGRAM?
• A computer program is a list of instructions that tell the
computer what to do.
• Programs are written in programming languages.
• A collection of computer programs, libraries and other
related data are called software.
• Some examples of some software are: Windows 10, MS
Word, Adobe Photoshop etc.
WHAT IS A PROGRAMMING LANGUAGE?

• A programming language is a special purpose and limited


language.

• It has a set of rules and symbols (syntax) are used to construct a


computer program.

• Programming languages allow programmers to code software.

• Languages closer to the machine can be more efficient.


COMPUTER LANGUAGES
• The three major families of languages are:

Machine languages
Assembly languages
High-level languages
COMPUTER LANGUAGES

Machine languages Assembly languages High- level languages

Uses binary code Uses mnemonics Uses English-like language


Machine-dependent Machine-dependent Machine independent
Not portable Not usually portable Portable (but must be
compiled for different
platforms)
Examples: Pascal, C, C++,
Java etc.
MACHINE LANGUAGES
• Machine languages are comprised of 1s and 0s.
• Machine language is the “native” language of a
computer.
• Difficult to program – one misplaced 1 or 0 will cause
the program to fail.
Example
1110100010101 111010101110
10111010110100 10100011110111
ASSEMBLY LANGUAGES
• Assembly languages are a step towards easier
programming.
• Assembly languages are comprised of a set of elemental
commands which are tied to a specific processor.
• Assembly language code needs to be translated to machine
language before the computer processes it.
Example
ADD 1001010, 1011010
HIGH-LEVEL LANGUAGES
• High-level languages represent a giant leap towards
easier programming.

• A programming language which use statements


consisting of Englishlike keywords such as “FOR”, “IF” etc.
TYPES OF PROGRAMMING LANGUAGES
Imperative Languages
• Procedural Languages: C, FORTRAN, Pascal
• Object Oriented Languages: Java, Python, C#, C++
Declarative Languages
• Functional Languages: Some functional programming languages
can also be
Object Oriented programing languages, such as: OCaml and Scala.
EARLY HIGH-LEVEL PROGRAMMING
LANGUAGES
• Plankalkül (“Plan Calculus”) is considered as the first
high-level programing language. It was created by Konrad
Zuse between 1942 and 1945.

• First commercially available high-level programming


language was FORTRAN (FORmula TRANslation)
developed in 1956.
COMPILING
• Regardless of the High-level (HL) Language, all HL
programs need to be translated to machine code so that
a computer can process the program.
• Some programs are translated using a compiler. When
programs are compiled, they are translated all at once.
Compiled programs typically execute more quickly than
interpreted programs but have a slower translation
speed.
INTERPRETING
• Some programs are translated using an interpreter. Such
programs are translated line-by-line instead of all at
once like compiled programs. Interpreted programs
generally translate quicker than compiled programs but
have a slower execution speed.

PHP, Perl, Ruby, Python etc.


WHAT IS C AND WHY C?
• C is a general purpose, procedural computer
programming language. C was designed by Dennis
Ritchie at Bell Labs between 1972 and 1973.

• Why do we learn C in this module?

• Why not other languages?


C has Become Very popular for Various
Reasons
• One of the early programming languages.
• Still, the best programming language to learn quickly.
• C language is reliable, simple, and easy to use.
• C language is a structured language.
• Modern programming concepts are based on C.
• It can be compiled on a variety of computer platforms.
• Universities preferred to add C programming in their
courseware.
Features of C programming Language
• C is a robust language with a rich set of built-in functions
and operators.
• Programs written in C are efficient and fast.
• C is highly portable; programs once written in C can be
run on other machines with minor or no modification.
• C is a collection of C library functions; we can also create
our function and add it to the C library.
• C is easily extensible.
Advantages of C
• C is the building block for many other programming
languages.
• Programs written in C are highly portable.
• Several standard functions are there (like in-built)
that can be used to develop programs.
• C programs are collections of C library functions,
and it's also easy to add functions to the C library.
• The modular structure makes code debugging,
maintenance, and testing easier.
Disadvantages of C
• C does not provide Object Oriented Programming
(OOP) concepts.

• There are no concepts of Namespace in C.

• C does not provide binding or wrapping up of data


in a single unit.

• C does not provide Constructor and Destructor.


The limitations of C programming languages are as
follows:
• Difficult to debug.
• C allows a lot of freedom in writing code, and that is why you can put an
empty line or white space anywhere in the program. And because there is no
fixed place to start or end the line, so it isn't easy to read and understand the
program.C compilers can only identify errors and are incapable of handling
exceptions (run-time errors).
• C provides no data protection.
• It also doesn't feature the reusability of source code extensively.
• It does not provide strict data type checking (for example, an integer value can
be passed for floating datatype).
Structure of basic C program
Include something

#include <stdio.h>
#include <stdlib.h> Header file

int main(void) Main funtion


Begin of the
program
{

Display printf ("Hello world!\n");


Body
return 0;
End of the
program }
YOUR FIRST C PROGRAM
COMMENTS
• You insert comments to document programs and improve
program readability.

• Comments do not cause the computer to perform any


action when the program is run. They’re ignored by the C
compiler do not cause any machine-language object code
to be generated.

• Helps other people to read and understand you program.


COMMENTS
Ex:-
Ø /*
Main function Multi-line
comment
*/

Ø // your first C program Single-line


comment
BLANK LINES AND WHITE SPACE

• You use blank lines, space characters and tab


characters (i.e., “tabs”) to make programs easier to
read. Together, these characters are known as
whitespace. White-space characters are normally
ignored by the compiler.
#INCLUDE PREPROCESSOR DIRECTIVE
• #include <stdio.h> is a directive to the C preprocessor. Lines
beginning with # are processed by the preprocessor before
compilation.
#include <stdio.h>
• The following line tells the preprocessor to include the contents
of the standard input/output header (<stdio.h>) in the program.
• This header contains information used by the compiler when
compiling calls to standard input/output library functions such as
printf.
THE ‘MAIN’ FUNCTION
• The main function is a part of every C program.
• The parentheses after main indicate that main is a
program building block called a function.
• C programs contain one or more functions, one of
which must be main.
• Every program in C begins executing at the function
main.
Int main (void)
THE ‘MAIN’ FUNCTION
• A left brace, {, begins the body of every function. A
corresponding right brace, }, ends each function. This
pair of braces and the portion of the program
between the braces is called a block. The block is an
important program unit in C.

int main (void)


{

}
THE ‘MAIN’ FUNCTION
• Functions can return information. The keyword int to the
left of main indicates that main “returns” an integer
(whole-number) value. In this example, the value ‘0’ is
returned from the function using a return statement. We’ll
discuss about functions in detail later in this module.

int main (void)


{
return 0;
}
THE OUTPUT STATEMENT
• The following line instructs the computer to
perform an action, namely to print on the screen
the string of characters marked by the quotation
marks.
printf (“Hello World”);
• A string is sometimes called a character string, a
message or a literal.
• The entire line, including the printf function
(the “f” stands for“formatted”), its argument
within the parentheses and the semicolon (;), is
THE OUTPUT STATEMENT
• Every statement must end with a semicolon (also known
as the statement terminator).

• When the preceding printf statement is executed, it prints


the message Hello World on the screen. The characters
normally print exactly as they appear between the double
quotes in the printf statement.

printf (“Hello World”);


COMPILING AND EXECUTING A C PROGRAM
• The following command can be is used to compile (and link) a C program
(named ‘HelloWorld.c’) using the GNU C compiler. This will create an
executable file named ‘a.exe’.

• To specify your own filename for the executable file instead of the default
filename, following command can be used.

• After compiling the program, you can run the executable file that was
created.
**HAPPY CODING**

You might also like