You are on page 1of 21

INTRODUCTION TO

COMPUTER PROGRAMMING

WITH C

Author:

Ghullam Mohiyuddin

(BCS, D.A.E-IT)

Sr. Instructor (C.I.T) in Abbas College of Technology

0303-4875291, 0340-4088566

Compile By:
Attested From: Owais Jamil
Engr. M Shumraiz Sharif (BS-Electrical Engineering)
(BS-(IT), D.A.E-IT, CCNA, ITP) H.O.D (ET)
Sr. Instructor & (H.O.D)

mshumraizsharif@gmail.com
C Language Notes Master Solution for Exams GMD©

Source code

A computer program that are written in high level language is called the source
program.

In computing, source code is any collection of computer instructions, possibly with


comments, written using a human-readable programming language, usually as
ordinary text.

Object code

A computer program in machine language is called object program/code.

OR

Code produced by a compiler or assembler

-------------------------------------------------

2-Define program and programmer?

Program

A well-defined set of instruction for computer to perform a specific task is called


the computer program.

Programmer

A person who develop/write the program is known programmer or developer.

--------------------------------------------------

What is Language and type name?

The language is the rule, set of instruction in which a program create/develop.

Types

pg. 2
C Language Notes Master Solution for Exams GMD©
 High Level Language (C,C++,C#, java, php)
 Low Level Language(like machine , assembly language)

--------------------------------------------------

3-Define Flow chart and IDE

Flow Chart

The sequence and step-by-step designing and representation of the algorithm is called flow
chart

--------------------------------------------------

4-Define variable. Also define the constant and global variable.

Variable

Variables are locations in memory for storing data.

Constant Variable

The value of variable which cannot be changed during the execution of program. It must be
numeric type.

Global Variable

The value of variable which can change outside to the program boundary.

--------------------------------------------------

5-Write the step to create the C program.

There are five steps to create C program

1-Creating source program

2-Saving the source Program

3-Compiling the source program

4-Linking

5-Loading

pg. 3
C Language Notes Master Solution for Exams GMD©
-------------------------------------------------

6-Define HLL and LLL. Also define advantages.

High Level Language

The language that are close to human language is known high level language. For example
English, Urdu, in computing C++, C#, php are high level language.

The advantage of high level language is that we can easily write the program in our
language like English, which human (programmers) can easily understand.

Low Level Language

The language that is close to machine is called low level language, like assembly binary
language, in which computer communicate between their components. It is also called
machine language.

The advantages of machine language is that the computer easily understand their native
language like assembly or binary language.

--------------------------------------------------

Define Compiler and assembler.

Compiler

The program that translate the source program into machine language is called compiler.

Assembler

The application that translate the assembly language program into machine language is
called assembler.

7-Define source code and why it cannot direct execute.

The computer that are written in high level language is called source code. It cannot be
direct execute because as we know that computer is a machine and it understand the
machine language , but our program code writer in high level language(human language)
pg. 4
C Language Notes Master Solution for Exams GMD©
.Therefor a program which name compiler is use that convert source code into machine
language(object code) .

---------------------------------------------------

Define ANSI.

ANSI stand for American National Standard Institute which developed a standard for C
language in late 80s.This standard version of C language is known as ANSI C.

---------------------------------------------------

8-What is getch () function?

The getch () stand for get character. This function is used to get a single character from the
keyboard during program execution. When a key pressed on the keyboard.

----------------------------------------------------

9-Define bug and debug.

Bug

The error which come in program are called bug. The bug is occur when the program syntax
is not write according to standard of the language.

Debugging

Removing the error from program is called debugging.

-----------------------------------------------------

10-Define type casting.

Conversion of data type of a numeric value into another data type during arithmetic
operation is called casting or type casting.

------------------------------------------------------

11-Write down the operation of /n?

It is a function in C language programming for create a new line in program.

-------------------------------------------------------

12-Define function and syntax.


pg. 5
C Language Notes Master Solution for Exams GMD©
Function

The function is the well-define procedure of the event which is perform their specific
operation in program.

Syntax

The syntax is the writing style and predefine standard in any programming language.

--------------------------------------------------------

13-Define linker write the process of linking.

In C program there are many associate predefined routines and functions. The function are
functions are contained in separate files. This file are part of C compiler and called library
files/runtime file. The C program needs the library file for execution of the program
creation. The file combine with object program.

The process of combining the required library with the object program is called linking. The
program who perform this process of linking called linker.

--------------------------------------------------------

14-Define loop and Nested loop.

Loop

Loop is also called the repetition structure .The loop is control structure which are repeat
and again and again in program.

Nested Loop

A loop structure completely inside the body of another loop structure is called nested loop.

---------------------------------------------------------

15-What is assignment statement?

The statement that is use to assign a value to a variable is called an assignment statement.

---------------------------------------------------------

16-What is operator? Also explain relational operator.

Operator

pg. 6
C Language Notes Master Solution for Exams GMD©
An operator is a symbol or an identifier that represent some action which is performed on
data.

Relational Operator

The relational operator is use to compare two expressions. Relational operator return value
true or false.

---------------------------------------------------------

17-Give the name of Relational Operator.

There are following given the name of relational operator

Greater than >

Greater than or equal >=

Less than <

Less than or equal <=

Assignment =

Not equal to !=

Equal ==

------------------------------------------------------

18-Define function and Declaration.

Function

A Functions is a piece of code that designed to perform a specific task. Which we are using
in our program to make a standard or some action of event executable code and this process.

Declaration

Variable declaration tells the computer the name and the data type of the variable that is to
be used in a program.

-----------------------------------------------
pg. 7
C Language Notes Master Solution for Exams GMD©
19-Define Logical Operator.

The logical operator are used to make compound condition. The output of logical operator is
True or False.

-----------------------------------------------

20-Define Syntax error.

The rules for writing statements in a computer programming language is called syntax of the
language. All program written according to these rule. A single mistake in these rule causes
an error .This error is called syntax error.

---------------------------------------------

21-Define while loop.

It is a conditional loop statement. It is used to execute a statement or a set of statement as


long as given condition remain true.

----------------------------------------------

22-Define statement and Return statement.

Statement

The statement of a C program are written under the main () function between curly braces
{}. The statement is the code in programming language.

Return Statement

The return statement are used to return a function or attribute of property in programming.

---------------------------------------------

23-What is expression explain?

An expression is used for calculating the value of formula. It is form by combining different
operand and operator.

----------------------------------------------

24-What is pointer?

A pointer is basically a variable like any other variable. However, the pointe is containing
actual data. Containing the address of the memory location.

----------------------------------------------
pg. 8
C Language Notes Master Solution for Exams GMD©
25-Define string and compound condition.

String

The string is the character data type. String containing the alphabetic and numeric data type.

26-Define Escape Sequence.

A combination of characters are used to control printing on the output device. This
combination of the character is called escape sequence.

----------------------------------------------

28-Define for loop in C language.

For statement/loop is used to execute a set of statements repeatedly for the specific number
of times. It is also known as counter loop.

-----------------------------------------------

29-What is! = ?

!= is the not equal operator in programming.

----------------------------------------------

30-What is the purpose of main function?

The main function is point by all program start their execution, independently, of its location
within the source code. The word main is followed the in the code by a pair of parentheses ().

---------------------------------------------

31-Define increment operator.

++ is an increment operator, Increment operator increases integer value by one A++ will
give 11.

-------------------------------------------------------

32-Define iteration structure.

The iteration structure is a also called loop structure. The iteration/loop is control structure
which are repeat and again and again in program.

34-What is implicit casting?

pg. 9
C Language Notes Master Solution for Exams GMD©
An arithmetic operator involve two numeric value can only be performed if the value are of
the same types. If the value are of different data types, then the value within a lower order
data type is converted into the data type of the value.

-------------------------------------------------------

35-Describe file opening module.

Before reading or writing data in data file, it must be opened. When a file is opened, a
portion of memory is reserved associated with the file. This section of memory is used to
temporarily store data being read from or written into the file.

--------------------------------------------------------

36-What is binary file?

The binary file is the sequence of bytes or binary digits (0, 1). The number of bytes written
or read in always the same as those on the external device.

--------------------------------------------------------

37-Define if else statement.

It is used to making two-way decision. In this statement, one condition and two block of the
statement are given.

If the one block is true then it execute, else the second block is execute.

---------------------------------------------------------

38-Describe get ch () function.

The “get ch ()” stands for get character. This function is used to get a character from the
keyboard during program execution.

--------------------------------------------------------

39-What is function call?

Function call is mechanism that is used to invoke or execute a function. Function in invoke
to perform the specific task for which it had been written.

--------------------------------------------------------
pg. 10
C Language Notes Master Solution for Exams GMD©
40-Define Array.

Collection of string data type. That hold multiple variables of one type, allowing index
access to the individual value.

-----------------------------------------------------

41-Define bug and debug.

Bug

The error which come in program are called bug. The bug is occur when the program syntax
is not write according to standard of the language.

42-Define Arithmetic Operator.

Arithmetic operator are the symbols that are used to represent arithmetic operation. These
are used in arithmetic expression.

+, - ,* , / , % are example of arithmetic operator.

-----------------------------------------------------

43-Define BOF AND EOF.

BOF

A data file in C consists of a series of bytes. It has a beginning and end. The start of the first
byte in the file is called Beginning of File (BOF). The end of last file is called End of File
(EOF).

------------------------------------------------------

44-What is initialization of Variables?

The initialization of variable mean that the value is assigned to it at the time of its
declaration. Assigning known value to be variable at the time of its declaration is called
initialization of variable.

----------------------------------------------------
pg. 11
C Language Notes Master Solution for Exams GMD©
45-What is mean by graphic mode?

The graphic mode represent the coloring and designing the objects of the program.

----------------------------------------------------

46-Define control structure.

The statement of the computer program are executed one after the other in the order in
which they are written. This known as sequence of flow. The control structure are
statement that are use control flow of the execution in the program. A control structure
consists of a group of statement.

-----------------------------------------------------

47-What is IDE?

IDE stand for Integrated Development Environment which is the complete package of the
tools for design the program layout and sketch. There are different of developing tools for
uses.

48-What is Language Processor?

The language processor is a program which interpret the logic and the sequence of the
programs. It is associate with program library and consists the principle and standard syntax
of language. Each programming language have their own processor to process the source
code.

----------------------------------------------------

50-Briefly explain the history of C language.

C is general purpose programming language. It was develop Bell Laboratories, USA in


1972. It was design by Dennis Ritche. It was based on earlier computer language called B.
After called C language. It is develop for UNIX operating system.

---------------------------------------------------

What is SVGA?
SVGA stand for Super Video Graphics Array.It is low level graphics programming using c with inline
assembly.

---------------------------------------------------------------

pg. 12
C Language Notes Master Solution for Exams GMD©
BCPL ("Basic Combined Programming Language")

is a procedural, imperative, and structured computer programming language designed by Martin Richards
of the University of Cambridge in 1966.

---------------------------------------------------------------------

What is EOF?

In computing, end-of-file (commonly abbreviated EOF) is a condition in a computer operating system


where no more data can be read from a data source. The data source is usually called a file or stream.

---------------------------------------------------------------------------

What is programming cycle?

 Problem definition
 Problem Analysis
 Algorithm Development
 Coding & Documentation
 Testing & Debugging
 Maintenance

Cite advantages and dis-advantages of flow chart. 20 FEB

pg. 13
C Language Notes Master Solution for Exams GMD©

Advantages and Disadvantages of Flowchart

Advantages of Using FLOWCHARTS:

• Communication: Flowcharts are better way of communicating the logic of a system to all concerned or involved.
• Effective analysis: With the help of flowchart, problem can be analyzed in more effective way therefore reducing cost
and wastage of time.
• Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various
purposes, making things more efficient.
• Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and program development phase.
• Proper Debugging: The flowchart helps in debugging process.
• Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It
helps the programmer to put efforts more efficiently on that part

Disadvantages Of Using FLOWCHARTS:


• Complex logic: Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy.
This will become a pain for the user, resulting in a waste of time and money trying to correct the problem
• Alterations and Modifications: If alterations are required the flowchart may require re-drawing completely. This will
usually waste valuable time.
• Reproduction: As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem.

Explain Functions

A function is a group of statements that together perform a task. Every C program has at least one function, which is
main(), and all the most trivial programs can define additional functions. You can divide up your code into
separate functions

What is Pointer?

A pointer is a variable which contains the address in memory of another variable.


We can have a pointer to any variable type. The unary or monadic operator & gives
the ``address of a variable''. The indirection or dereference operator * gives the
``contents of an object pointed to by apointer''.

pg. 14
C Language Notes Master Solution for Exams GMD©

Chapter # 8

Array and String

Array
In programming, a series of objects all of which are the same size and type. Each
object in an array is called an array element. An array is a collection of data items,
all of the same type, accessed using a common name. A one-dimensional array is
like a list; A two-dimensional array is like a table; The C language places no limits on
the number of dimensions in an array, though specific implementations may.

Array data structure, or simply an array, is a data structure consisting of a


collection of elements (values or variables), each identified by at least
one array index or key. An array is stored so that the position of each element can
be computed from its index tuple by a mathematical formula.

Types of Array
There are two types of array

1-One Dimension Array

2-Two Dimension Array

One Dimension Array


A one-dimensional array (or single dimension array) is a type of linear array.
Accessing its elements involves a single subscript which can either represent a row
or column index. As an example, consider the C declaration int anArrayName[10];

pg. 15
C Language Notes Master Solution for Exams GMD©

Two Dimension Array


Two-dimensional Arrays. ... The elements of a 2D array are arranged in rows and
columns, and the new operator for 2D arrays specifies both the number of rows and
the number of columns. For example, int[][] A; A = new int[3][4];

String
In computer programming, a string is traditionally a sequence of characters, either
as a literal constant or as some kind of variable. The latter may allow its elements to
be mutated and the length changed, or it may be fixed (after creation).

A string in C is merely an array of characters. The length of a string is determined by


a terminating null character: '\0' . So, a string with the contents, say, "abc" has four
characters: 'a' , 'b' , 'c' , and the terminating null character. The terminating null
character has the value zero.

pg. 16
C Language Notes Master Solution for Exams GMD©

Chapter # 9

Pointer

Pointer
In computer science, a pointer is a programming language object, whose value
refers to (or "points to") another value stored elsewhere in the computer memory
using its memory address. A pointer references a location in memory, and obtaining
the value stored at that location is known as dereferencing the pointer.

how to Return Data from Functions

Functions that return values are sometimes called fruitful functions. In many other
languages, a function that doesn't return a value is called a procedure

Use of Double Indirection: Pointers to Pointers

The most common form of indirection is the act of manipulating a value through its
memory address. For example, accessing a variable through the use of a pointer. A
stored pointer that exists to provide a reference to an object by double indirectionis
called an indirection node.

pg. 17
C Language Notes Master Solution for Exams GMD©

Chapter # 10

Structures and Unions

A struct in the C programming language (and many derivatives) is a composite


data type (or record) declaration that defines a physically grouped list of variables to
be placed under one name in a block of memory, allowing the different variables to
be accessed via a single pointer, or the struct declared name which…

A union is a special data type available in C that allows storing different data types
in the same memory location. You can define a union with many members, but only
one member can contain a value at any given time. Unions provide an efficient way
of using the same memory location for multiple purposes.

Unions provide an efficient way of using the same memory location for multiple
purposes. Both are user-defined data types used to store data of different types as a
single unit. Their members can be objects of any type, including
other structuresand unions or arrays.

pg. 18
C Language Notes Master Solution for Exams GMD©

pg. 19
C Language Notes Master Solution for Exams GMD©

Chapter # 11

Files
The C language provides a set of rich library functions to perform input andoutput (I/O) operation. Those
functions can read or write any type of data to files. Before we go any further in discussing the C
I/O functions, let's first understand the definitions of files and streams in C.

stdio.h. There are types and functions in the library stdio.h that are used for file I/O. Make sure you always
include that header when you use files. ... Functions. Reading from or writing to a file in Crequires
3 basic steps: ... filename is a string that holds the name of the file on disk (including a path like /cs/course
if necessary).

A file with associated buffering is called a stream and is declared to be a pointer to a defined type FILE. ...
The following symbolic values in <unistd.h> define the file descriptors that is associated with the C-
language stdin stdout and stderr when the application is started: STDIN_FILENO. Standard input
value stdin.

The C language provides a set of library functions to perform input and output(I/O) operations.
Those functions can read or write any type of data to files. In C, a file can refer to a disk file, a terminal, a
printer, etc.

Binary and Text Mode Files

pg. 20
C Language Notes Master Solution for Exams GMD©
All files are saved in one of two file formats - binary or text. ... While both binary and text files contain
data stored as a series of (bits (binary values of 1s and Os), the bits in text files represent characters,
while the bits in binary files represent custom data.

In text mode, a newline character is converted into the carriage return-linefeed combination before being
written to the disk. Likewise, the carriage return-linefeed combination on the disk is converted back into a
newline when the file is read by a C program. However, if a file is opened in binary mode,

Random Access Files

Writing Data Randomly to a Random-Access File. The program writes data to


the file "credit.dat". It uses the combination of fseek and fwrite to store data at
specific locations in the file. Function fseek sets thefile position pointer to a
specific position in the file, then fwrite writes the data.

Error Handling in File I/O

Error Handling Functions. There are several error


handling functions supported by class ios that help
you read and process the status recorded in a file
stream. Returns a non-zero value if an invalid
operation is attempted or any unrecoverable error has
occurred.

Redirection
I/O Redirection in C++ ... C++ being an object-oriented programming
language gives us the ability to not only define our own streams but
also redirect standard streams. Thus in C++, a stream is an object
whose behavior is defined by a class. Thus anything that behaves like a
stream is also a stream.

GOOD LUCK!
pg. 21

You might also like