0% found this document useful (0 votes)
36 views24 pages

Lesson 1-Introduction To Fundamentals of Programming

Dennis Ritchie created the C programming language in 1972. C is a procedural language that is fast and can directly access hardware, making it well-suited for system programming like operating systems and drivers. It became popular for writing application software as well. Bjarne Stroustrup expanded on C to create C++ in 1979, adding object-oriented programming features while maintaining C's performance. The document then provides examples of simple C programs to print messages and demonstrates basic syntax like functions, libraries, and string output.

Uploaded by

janlixalmendral
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
0% found this document useful (0 votes)
36 views24 pages

Lesson 1-Introduction To Fundamentals of Programming

Dennis Ritchie created the C programming language in 1972. C is a procedural language that is fast and can directly access hardware, making it well-suited for system programming like operating systems and drivers. It became popular for writing application software as well. Bjarne Stroustrup expanded on C to create C++ in 1979, adding object-oriented programming features while maintaining C's performance. The document then provides examples of simple C programs to print messages and demonstrates basic syntax like functions, libraries, and string output.

Uploaded by

janlixalmendral
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 24

Lesson 1

Introduction to Fundamentals of
Programming
What is C?
Dennis Ritchie created C in 1972 to enable utilities to run on
Unix. C is a systems programming language, which means
that it operates at the most fundamental level of abstraction
possible.
It is a procedural language at the lowest level. Because C
programs are fast, they enable developers to manage
computer hardware manually.
The strength of the C programming language is that it is fast
and can be used to write code for a broad number of
systems. It is a programming language that is frequently
used in operating systems, interpreters, compilers, and
microcontrollers.
Similarities between C and C+
+
What is C++?
Bjarne Stroustrup created C++ in 1979 while working at Bell
Labs. He desired a versatile and efficient expansion of C. C++ is
object-oriented, yet like C, it may be used on a wide variety of
systems.

Additionally, manual memory management is supported. C++ is


an excellent programming language for networks, server-side, and
gaming applications.

The programming language is small, compiled, and portable


across a broad variety of systems. Indeed, the C++ programming
language is nearly identical to C, but it adds features..
Now that we have a basic understanding of both
languages, we will examine their commonalities. Due
to the fact that C++ is a superset of C, the two
languages have a common grammar, code structure,
and compilation. Almost all of C's keywords and
operators are applicable to C++ and perform the
same function.

Both C and C++ are top-down execution languages


that support procedural and functional
programming. Additionally, both languages utilize the
statement terminator ;. Additionally, they share the
stack, heap, file-scope, and static variables concepts.
As previously stated, both C and C++ are
computer languages that are used to
construct applications. The primary
difference between the two programming
languages is that C is a procedural language
that does not support classes or objects,
whereas C++ is a blend of procedural and
object-oriented programming languages.
The Origins and History of C
Dennis Ritchie developed C in its original form in the 1970‟s at Bell
Telephone Laboratories (Now it is AT&T Bell Laboratories). Earlier, Martin
Richard had developed a language by name BCPL and Ken Thompson
had developed a language B in the same Laboratory.
C was based upon the two languages. Brian Kernighan and Dennis
Ritchie published a definite description of the language C (Prentice Hall,
1978).
This description of the language is known as K&R C. With this the
popularity of C became widespread. Many different compilers were
written all of which did not stick to the same definition as K&R C.
Because of the popular features of C many commercial product were
rewritten using C.
As the popularity grew, many commercial houses
developed their own compiler for C. As a result the
differences from K&R C started appearing.
This resulted in non-compatible and non-portable
programs even though the language was same. American
National Standards Institute (ANSI) came forward to define
a standard definition of the language and formed the
committee X3J11 (early summer, 1993) for this purpose.
The ANSI standard for C language was officially adopted in
1990. The commercial C compiler is expected to follow this
standard.
This module explains the language as defined by Kernighan
and Ritchie. Most of the commercial C compilers today
would support this. However, there can be few variations.
The best way to learn a programming language is to write programs
using the language.

Let us start by writing a program in C language.


First Example
Our program will print a message on the screen “My first C program
is here!”
The following program does it.

#include<stdio.h>
int main()
{
printf(“\nMy first C program is here!\n”);
}
The above is a program code to print a
message on the screen „My first C program is
here!‟ It has to be entered into the computer
memory through the keyboard with the help
of an editor program, it has to be compiled
and run so or execute so that the result is
visible to us.
How to perform these steps depends on the
system you are using or what C compiler you
are using.
Use the Online C compiler IDE JDoodle or Online C
compiler
In your browser type Online C compiler IDE Jdoodle
Let us try to code the first example in the Online C
compiler IDE JDoodle
Using Online C compiler
In your browser type Online C Compiler
Let us try to code the first example in the
Online C compiler

It will produce the following on the screen as


the output. My first C program is here!
Let's understand the example program.
The first line is to incorporate a library
function. If in a program you intend to use
any library function you have to give #include
statement.
The format of the statement is #include .
Here we are using one basic output function
printf (appearing later).The reference of this
function is the header file which is stdio.h; so
that the statement is #include.
A library function can be called anywhere in the
program. However, for a library function to be called
we have to include corresponding header file
(#include) at the starting of the program text.

We will discuss different library functions and the


required files to be included as and when their
inclusion becomes a requirement.
The second line of our program defines the int main
function that we are going to write. int (integer) is a
Data types. C program will consist of one or more
functions. The functions specify computing
operations to be performed.
In the above example, main is a function. main function can
call other function an in every C programs there will be a
main function. The main function can call other functions
written by the programmer or some function prewritten in
the library.
In above example, printf is a library function. It is called from
the main function. When a function is defined by
programmer, (not a library function) the function name is,
followed by the parentheses to enclose the arguments to be
supplied while calling it.
At the close of the parentheses follow the braces { }. The
braces enclose the statements that make up the function
body (e.g.,main() { }).
The function main () is automatically called when the
program is run. It should not be called from anywhere else in
the program.
The third line makes use of the library function printf. While calling
a function it is possible to pass on data to function to operate
upon.
The function printf in the example has a string “\nMy first C
program is here!\n” with double quote marks and within
parentheses. This is the data passed to printf function.
The printf function takes this argument and print or displays it on
the screen.
The printf statement ends with a semicolon (;). Every individual
statement in C ends with a semicolon (;).
If a number of statements are to be clubbed together then those
are enclosed within the braces { }. Such collection of statements is
called a compound statement.
We will see the use of this later. The character within “ ” (The two
double quote marks) inside the parentheses of printf statement are
called character string or string constant or control string.
A string of characters enclosed in double quotes is a string constant
and the string without the quote marks is also called a literal.
Within character and string constants, the backslash
character \ is special and is used to represent characters not
easily typed on the keyboard or for various reasons.
The control string of the printf function in the example
contains two special character \n one at the beginning and the
other at the end Through printed in two characters the two \n
are actually treated as a single character by the compiler, to
indicate that a new line should be introduced.
If \n is placed the beginning then the first a new line is
introduced and then the printing takes place. In the case of
example, a new line is introduced at the beginning. So the
message will be printed in a new line.
A new line is introduced at the end also because another \n is
there at the end of the printf argument which means further
print will be again in a new line.
If we write the statement for printing as follows, still
get the same effect.
printf (“\n My first”);
printf (“c program”);
printf (“is here! \n”);
Printing starts in a new line because of the first \
n.
So My first gets printed in a new line. Second
printf control statement does not have any \n in
it.
So c program gets printed by the side of My first.
The third printf does not have any \n at the start.
So this printing takes place in the same line as
earlier.
After printing is here! In the same line, printing to
the start point of a new line.
So, we get a print of the line as follows:
My first c program is here!
The combination characters like \n are called escape
sequences.
The most common combination escape sequences are:
\n a newline character
\b a backspace
\r a carriage return (without a line feed)
\t horizontal tab
\0 null
\‟ a single quote (e.g., in a character constant)
\” a double quote (e.g., in a string constant)
\\ a single backslash
\a alert bell
// notes or comments
For Example, print (“he said \”good morning\” ”); we will print
double quotes on good morning,
He said “good morning”
printf (“he said \”A\‟ is an English alphabet”); will print he
said “A‟ is an English alphabet
Points to be noted with our progress so far.
1. There are some library functions in C like printf,
etc.
2. Any C program will have a main () function
which is the start of the program.
3. Mostly characters used in C are in lower case.
4. Every statement ends with a; semicolon.
5. printf statement is used for providing output.

You might also like