0% found this document useful (0 votes)
11 views12 pages

XII-computer notes Chapter 3

Chapter 3 provides an overview of the C programming language, detailing its features, structure, and the Integrated Development Environment (IDE) used for development. It explains the steps to create a C program, the distinction between arguments and parameters, and the types of comments in C. Additionally, it covers escape sequences and their purposes, enhancing understanding of C programming fundamentals.

Uploaded by

jamil sulaiman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views12 pages

XII-computer notes Chapter 3

Chapter 3 provides an overview of the C programming language, detailing its features, structure, and the Integrated Development Environment (IDE) used for development. It explains the steps to create a C program, the distinction between arguments and parameters, and the types of comments in C. Additionally, it covers escape sequences and their purposes, enhancing understanding of C programming fundamentals.

Uploaded by

jamil sulaiman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Chapter 3 (AN OVERVIEW OF ‘C’ LANGUAGE)

Q1. What is C language?


Ans. C Language:-
1. C is a powerful programming language developed by Dennis Ritchie at Bell (now AT &
T’s Bell) Laboratories of USA in 1972. It is a structured programming
2. Its large variety of operators and commands can be used to write anything from operating
system to accounting packages. In fact, many of the C compilers on the market today
were written in C.
3. It is capable of handling a wide variety of system applications.
4. C is a portable language
5. It is a block structured language,
6. It has execution speed. C is closer to assembly language than other high level language
because some C commands directly address the physical hardware of the computer.

Q2. What is IDE? Write few shortcut keys and their function in IDE.
Ans. IDE (Integrated Development Environment):-An integrated development environment
(IDE) is software for building applications or programs that combines common developer tools
into a single graphical user interface (GUI). IDE serves as a single environment for most of a
Programmers don't need to switch between different tools to design a layout, write the code,
compilation, linking, build, loading, and debugging tools. IDE combines all tools that need for
development. Code completion capabilities improve programming workflow. Many IDEs
incorporate basic spelling checkers, so automatically check for errors to improve code.
The following are some programming languages use IDE such as Eclipse ( C, C++, Python,
Perl, PHP, Java, Ruby etc).
IDE shortcut keys:-
1. New (Ctrl+N) new opens a new Edit window with the default name NONAME.CPP
2. Open (F3) open and load an existing file into an edit window.
3. Save (F2) the save command saves the file that is in the active edit window to disk.
4. Undo (Alt+Bksp) the undo command takes back the last editing command we performed
on a line.
5. Redo (shift+Alt+BkSP) the redo command reverses the effect of the most recent undo
command.
6. Cut (shift+Del) the cut command removes the selected text block from our document and
places it on the clipboard.
7. Copy (Ctrl+ins) The copy command copies a selected text block and puts a copy on the
clipboard.
8. Paste (shift+ins) the paste command puts text from the clipboard into the current window.
Function Of IDE:-
1. Serves as a single environment for most of a developer’s need such as compilation,
linking, loading, and debugging tools.
2. Programmers don't need to switch between different tools to design a layout, write the
code, debug, build, etc
3. IDE combines all tools that need for development.
4. Automatically checks for errors to ensure top quality code.
5. Code completion capabilities improve programming workflow.
6. Refactoring capabilities allow developers to make comprehensive and mistake free
renaming changes.
7. Many IDEs incorporate basic spelling checkers, so automatically check for errors to
improve code.

Q3. How many steps are required to create any C program.


1. Writing Source Code of a Program:- This is using the language of programming to
write the lines of code. The code is also called source code, to save the source file
extension of .CPP
2. Debug the Source Code of a Program:- The computer user must debug the source code
of a program, if identified by the compiler called bug.
3. Compilation of Source Code of a Program:- Compiler compile the whole source code
of a program in to machined code that is called object code all at once, the object file
extension is .OBJ
4. Creating an Executable File of a Program:- A library is a collection of linkable files
that were supplied with compiler, link OBJ file with any needed libraries to produce an
executable program with extension of .EXE
5. Loading a Program File into RAM:- Before a program is executing it must be placed in
memory or RAM, it is done by the loader.
6. Execution of Program File by CPU:- Finally CPU executes the program file by
processing, one instruction at a time.

Q4. Write the basic structure of C programming language?

#include<…..> (Header File)


#include<…..> (Header File)

Void main(void) (Function name)


{ (Start of Function)
Statement 1;
Function Statement 2;
Body
…………..
} (End of Function)

1. # include <stdio.h> This command is a preprocessor directive in C that includes all


standard input-output files before compiling any C program so as to make use of all those
functions in our C program. This #include directive tells the compiler to use the
information in the header file called stdio.h. C makes use of a collection of libraries. The
standard input/output library is included via a header file called stdio.h. The header file is
not actually the input/output library, but a set of declarations and definitions that add
features to the I/O library. The use of angle brackets means to either look the header file
in the root directory or to begin looking for he header file in the user’s directory.
2. void main(void) – This is the line from where the execution of the program starts. The
main() function starts the execution of any C program. The void before main specifies
that the function main() will not return a value. The second void in the parentheses
specifier that the function takes not argument
3. { (Opening bracket) – This indicates the beginning of any function in the program (Here
it indicates the beginning of the main function).
4. /* some comments */ – Whatever is inside /*——-*/ are not compiled and executed;
they are only written for user understanding or for making the program interactive by
inserting a comment line. These are known as multiline comments. Single line comments
are represented with the help of 2 forward slashes “//——”.
5. printf(“Hello World”) –The printf() command is included in the C stdio.h library, which
helps to display the message on the output screen.
6. Scanf(): The scanf() function is a commonly used input function in the C programming
language. It allows to read input from the user or from a file and store that input in
variables of different data types.
7. getch() – This command helps to hold the screen.
8. return 0 –This command terminates the C program and returns a null value, that is, 0.
9. } (Closing brackets)- This indicates the end of the function. (Here it indicates the end of
the main function)
10. ; :- every statement must end with semicolon (also known as the statement terminator).
We can put several statements on a line. For clarity’s sake usually one statement is put on
a line.

Q5. Define arguments?


Arguments:-C programming function arguments also known as parameters are the variables
that will receive the data sent by the calling program. These arguments serve as input data to the
function to carry out the specified task.

Description of C programming function arguments


There are two types of arguments:
1. Actual arguments
2. Formal arguments
The variables declared in the function prototype or definition are known as Formal
arguments and the values that are passed to the called function from the main function are
known as Actual arguments.
Following are the two ways to pass arguments to the function:
1. Pass by value
2. Pass by reference

Pass by Value:-Pass by value is a method in which a copy of the value of the variables is passed
to the function for the specific operation.
In this method, the arguments in the function call are not modified by the change in parameters
of the called function. So the original variables remain unchanged.
Example of passing arguments by value to function in C
// arguments pass by value
# include <stdio.h>
int add (int a, int b)
{
return( a + b );
}
int main()
{
int x, y, z;
x = 5;
y = 5;
z = add(x,y); // call by value
return 0;
}
//end of program
In this program, function add() is called by passing the arguments x and y.
The copy of the values of x and y are passed to a and b respectively and then are used in the
function.
So by changing the values of a and b, there will be no change in the actual arguments x and y in
the function call.
Pass by reference:-Pass by reference is a method in which rather than passing direct value the
address of the variable is passed as an argument to the called function.
When we pass arguments by reference, the formal arguments in the called function becomes the
assumed name or aliases of the actual arguments in the calling function. So the function works
on the actual data.
Example of passing arguments by reference to function in C
// arguments pass by reference
#include <stdio.h>
void swap (int *a, int *b) // a and b are reference variables
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
int main()
{
int x = 2, y = 4;
printf("before swapping x = %d and y = %d\n", x, y);
swap(&x, &y); // call by reference
return 0;
} //end of program
In the above program, the formal arguments a and b becomes the alias of actual
arguments x and y when the function was called.
So when the variables a and b are interchanged x and y are also interchanged. So the output
becomes like this.
Output
before swapping x = 2 and y = 4
after swapping x = 4 and y = 2
Now, if the function was defined as:
void swap(int a, int b)
{
int temp;
temp = a;
a = b;
b = temp;
}
This is the pass by value method so here even if the values are swapped in the function the actual
value won’t interchange and output would become like this:
before swapping x = 2 and y = 4
after swapping x = 4 and y = 2
Q6. Define difference b/w argument and parameter?
Difference between Argument and Parameter
Argument Parameter

When a function is called, the values The values which are defined at the time of the
that are passed during the call are function prototype or definition of the function are
called as arguments. called as parameters.

These are used in function call


statement to send value from the These are used in function header of the called
calling function to the receiving function to receive the value from the arguments.
function.

During the time of call each


Parameters are local variables which are assigned
argument is always assigned to the
value of the arguments when the function is called.
parameter in the function definition.

They are also called Actual


They are also called Formal Parameters
Parameters

Example:
Example:
intCall(intrnum)
intnum = 20; {
Call(num) printf("the num is %d", rnum);
}
// num is argument
// rnum is parameter

Q6. Define comments in C. Also define its types.


Ans. COMMENTS IN C:The comments statements are those statements that are ignored by the
compiler. These statements do not execute. Through comments the programmers give special
remarks to the statements for their convenience. In C there are two types of comments
statement.
1. Single line Comment
2. Multi line Comment
SINGLE LINE COMMENT:-These are represented by two slash characters: //. It is used when
we have a one-line comment. All the text between // and the end of a line is ignored by the C
compiler. We can make single-line comments in many lines.
Example:
// This is my first C program
// This program displays a statement on screen
#include<stdio.h>:
int main( )
{
puts("My First C Program");
return 0;}
MULTI LINE COMMENT: This type is used to write multi line comment. These are
represented by /* ....*/ are used at the start and end of comment statements. It is used to have
comments in more than one line. All the text between /* and */ is ignored by the compiler.
Example:
/*This is my first C program
This program display a statement on screen.*/
#include<stdio.h>
int main()
{
puts("My First C Program");
return0:
}
Q7. What are escape sequences? Write the purpose of any three.
Ans. ESCAPE SEQUENCES: Escape sequences are used to control the cursor moves on screen
by using special codes. An escape sequence is a special non-printing characters consists of the
escape character (the backslash "\") and a second (code) character. The list of the escape
sequences is given below:
Regular Escape Sequences:
There are several escape sequence in C programming languages.
Escape Sequence Meaning

\a Alarm or Beep

\b Backspace

\f Form Feed

\n New Line

\r Carriage Return

\t Tab (Horizontal)

\v Vertical Tab

\\ Backslash

\' Single Quote

\" Double Quote


\? Question Mark

\nnn octal number

\xhh hexadecimal number

\0 Null

Now that we have a thorough understanding of each escape sequence in C,


Alarm or Beep (\a):
The alarm or beep escape sequence (a) produces an audible alert or beep sound.
#include <stdio.h>
int main() {
printf("This is an alarm sound: \a");
return 0;
}
Backspace (\b):
The cursor can be advanced by one character with the backspace escape key (b).
#include <stdio.h>
int main() {
printf("Hello\b\b\bWorld!");
return 0;
}
Form Feed (\f):
The form feed escape sequence (f) is used to mimic a page break or advance to the next page.
#include <stdio.h>
int main() {
printf("This is before the form feed.\fThis is after the form feed.");
return 0;
}
New Line (\n):
The new line escape sequence (n) is used to insert a newline character and move the cursor to
the start of the following line.
#include <stdio.h>
int main() {
printf("Line 1\nLine 2");
return 0;
}
Carriage Return (\r):
The cursor can be moved to the start of the current line by using the carriage return escape
sequence (r).
#include <stdio.h>
int main() {
printf("Hello\rWorld!");
return 0;
}
Tab (Horizontal) (\t):
The tab escape sequence (t) is used to insert a horizontal tab character and shift the cursor to the
following tab stop.
#include <stdio.h>
int main() {
printf("Name:\tJohn\tAge:\t25");
return 0;
}
Vertical Tab (\v):
The vertical tab escape sequence (v) is used to simulate a vertical tab or shift the mouse to the
following vertical tab location.
#include <stdio.h>

int main() {
printf("Hello\vWorld!");
return 0;
}
Backslash (\):
A backslash character is inserted using the backslash escape sequence (\).
#include <stdio.h>
int main() {
printf("This is a backslash: \\Hello");
return 0;
}
Single Quote ('):
The single quote escape sequence (') is used to insert a single quote character.
#include <stdio.h>
int main() {
printf("This is a single quote: \'Hello\'");
return 0;
}
Double Quote ("):
A double quotation character is inserted using the double quote escape sequence (").
#include <stdio.h>
int main() {
printf("This is a double quote: \"Hello\"");
return 0;
}
Question Mark (?):
The question mark escape sequence (?) is used to insert a question mark character.
#include <stdio.h>
int main() {
printf("This is a question mark: \?");
return 0;
}
Octal Number (\nnn):
The character's octal value can be inserted using the octal number escape sequence (nnn).
#include <stdio.h>
int main() {
printf("This is an octal value: \101");
return 0;
}
Hexadecimal Number (\xhh):
A character's hexadecimal value can be inserted using the hexadecimal number escape
sequence (xhh).
#include <stdio.h>
int main() {
printf("This is a hexadecimal value: \x41");
return 0;
}
Null (\0):
The null character, denoted by "0", is inserted using the null escape sequence (0).
#include <stdio.h>
int main() {
char myString[] = "Hello\0World!";
printf("String: %s", myString);
return 0;
}
Q8. What is main difference between source code and object code?
S.NO. SOURCE PROGRAM OBJECT PROGRAM
A collection of computer instructions written A sequence of statements in binary digits that is
1.
using a human readable programming language. generated after compiling the object program.
Contains English words according to syntax of
2. Contains binaries.
programming language.
3. Source code is another name for source program. Object code is another name for object program.
4. Programmers create the source program. Compilers create the object program.
5. It is the input to the computer. It is the output to the computer.
6. Programmers can read the source program Machines can read the object program.

Q9. What is the purpose of the statement # include<stdio.h> in a C program? What is


statement terminator
Ans. The file stdio.h is a built-in header file in C. The acronym stdio stands for Standard Input
and Output. This header file contains 3 variables, multiple function definitions, and multiple
macro definitions. These variables, functions, and macros are related to the input and output
operations in C.
Syntax to Include stdio.h in C
#include<stdio.h>
#include is a preprocessor directory in C. This keyword is used to include (or import) a header
file into our program.
If we want to use printf or scanf function in our program, we should include the stdio.h header
file in our source code.Otherwise, our program doesn’t know what is the definition of printf or
scanf and it will throw error/warning saying that implicit declaration of built-in function ‘printf’
#include is a preprocessor directory.It will include the file which is given within the angle
brackets "<>" into the current source file.
Example
If we use #include<stdio.h> in your c program, it will include stdio.h file into our source
program which has the information for all input, output related functions.

Q10. What is C preprocessor Directive? Define #define Or #include.


Ans. Preprocessor directives are lines of code that start with a ‘#’ symbol. They are used to
include header files, define macros, or perform conditional compilation. Examples of
preprocessor directives include ‘#include’, ‘#define’, and ‘#ifdef
A program which processes the source code before the source code is compiled is known
as preprocessor. The commands of the preprocessor are known as preprocessor directives. it
gets automatically processed due to the presence of preprocessor directives.
1. It is placed before the main().
2. It begins with a # symbol.
3. They are never terminated with a semicolon.
In programming terminology, a preprocessor is nothing but a System Software that performs the
processing of a high-level language before compilation by translating the source code written in
a high-level language to object code written in the machine-level language, that is easily
understood by the compiler.

Types of preprocessor directives.


1.Macro expansion
2. File inclusion
3.Conditional Compilation
Macro Expansion: the directive is written in #define is called macro. Macro substitution is the
process where an identifier in a program is replaced by a predefined string. The processor
replaces every occurrence of an identifier in the source code with string.
#define identifier string
#define PI 3.14
Macro with arguments:
The macro that accepts arguments is known as a macro arguments
#define identifier (a1,a2……aN) string
#define cube(X) (x*x*x)
File inclusion :-
The directive #include <filename> is used to include the contents of the file to the source
program
#include<filename.h>
#include<math.h>
The directive causes the contents of a file math.h to be included in our program so that all
functions of math.h can be used in our program.
The #include directive tells the compiler to use the information in the header file called stdio.h.
stdio.h stands for input/output and h stands for header file. The stdio.h file contains all the
instructions the compiler needs to work with disk files and send information to the screen.
Conditional compilation:- A conditional compilation directive causes the preprocessor to
conditionally suppress the compilation of portions of source code
#if, #else#ifdef etc
Void main()
{
#if(conditions)
Statement 1;
#else
Statement 2;
#endif
………;
}

You might also like