CC2 Reviewer

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

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.

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.

Similarities

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.

Difference

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.

Origin 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
products were rewritten using C.

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

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.

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

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.


The flowchart in the C
programming language
What do you mean by flowchart?

• The Flowchart is the most widely used


graphical representation of an algorithm
and procedural design workflows. It uses
various symbols to show the operations
and decisions to be followed in a program.
It flows in sequential order.

Types of Flowchart
The various types of the flowchart are given
below.
• Horizontal Flowchart
• Panoramic Flowchart
• Vertical Flowchart
• Architectural Flowchart

Rules or guidelines of Flow chart:


The various Rules or Guidelines for drawing
the flowchart are given below.
• Only conventional flowchart symbols should be
used.
• Proper use of names and variables in the
flowchart.
• If the flowchart becomes large and complex,
use connector symbols.
• Flowcharts should have start and stop points.
Uses of a flowchart:
• To specify the method of solving a problem.
• To plan the sequence of a computer program.
• Communicate ideas, solutions. Drawing a
flowchart
• Identify input and output.
• Apply reasoning skills to solve the problem.
• Draw the flowchart using the appropriate
symbols and arrows to show the sequence of
steps in solving the problem.

Flowchart symbols:

The different flowchart symbols have different conventional


meanings. The various symbols used in Flowchart Designs are given
below.

1. Terminal Symbol: In the flowchart, it is represented with the help of a


circle for denoting the start and stop symbol. The
symbol given below is used to represent the
terminal symbol.

2. Input/output Symbol:
The input symbol is used to represent the
input data, and the output symbol is used to
display the output operation. The symbol
given below is used for representing the
Input/output symbol.

3. Processing Symbol:
It is represented in a flowchart with the help
of a rectangle box used to represent the
arithmetic and data movement instructions.
The symbol given below is used to represent
the processing symbol.

4. Decision Symbol:
Diamond symbol is used for represents
decision-making statements. The symbol
given below is used to represent the
decision symbol.
5. Connector Symbol:
The connector symbol is used if flows
discontinued at some point and continued
again at another place. The following symbol
is the representation of the connector
symbol.

6. Flow lines:
It represents the exact sequence in which
instructions are executed. Arrows are used
to represent the flow lines in a flowchart. The
symbol given below is used for representing
the flow lines:

7 Hexagon symbol (Flat):


It is used to create a preparation box
containing the loop setting statement. The
symbol given below is used for representing
the Hexagon symbol.

8. On-Page Reference Symbol:


This symbol contains a letter inside that
indicates the flow continues on a matching
symbol containing the same letters
somewhere else on the same page. The
symbol given below is used for representing
the on-page reference symbol.

9. Off-Page Reference:
This symbol contains a letter inside
indicating that the flow continues on a
matching symbol containing the same letter
somewhere else on a different page. The
symbol given below is used to represent the
off-page reference symbol.

10. Delay or Bottleneck:


This symbol is used for identifying a delay in
a flowchart. The alternative name used for
the delay is the bottleneck. The symbol
given below is used to represent the delay
or bottleneck symbol.

11. Document Symbol:


This symbol is used in a flowchart to indicate
a document or report. The symbol given
below is used to represent the document
symbol.

12. Internal storage symbol:


The symbol given below is used to represent
the internal storage symbol.

Advantages of Flowchart in C
Following are the various advantages of flowchart:
• Communication: A flowchart is a better way of communicating the logic of a program.
• Synthesis: Flowchart is used as working models in designing new programs and software systems.
• Efficient Coding: Flowcharts act as a guide for a programmer in writing the actual code in a high-level language.
• Proper Debugging: Flowcharts help in the debugging process.
• Effective Analysis: Effective analysis of logical programs can be easily done with the help of a related flowchart.
• Proper Documentation: Flowchart provides better and proper documentation. It consists of various activities such as collecting,
organizing, storing, and maintaining all related program records.
• Testing: A flowchart helps in the testing process.
• Efficient program maintenance: The maintenance of the program becomes easy with the help of a flowchart.

Disadvantages of Flowchart in C: Following are the various disadvantages of flowchart:


• Time-consuming: Designing a flowchart is a very time-consuming process.
• Complex: It isn't easy to draw a flowchart for large and complex programs.
• There is no standard in the flowchart; there is no standard to determine the quantity of detail.
• Difficult to modify: It is very difficult to modify the existing flowchart.

You might also like