Structured - C - UNIT-I
Structured - C - UNIT-I
CLASS : I - B.C.A
SUBJECT : Foundation Course - Structured Programming Language in C
SYLLABUS
UNIT - I
Overview of C: Importance of C, sample C program, C program structure, executing C program. Constants,
Variables, and Data Types: Character set, C tokens, keywords and identifiers, constants, variables, data
types, declaration of variables, Assigning values to variables – Assignment statement, declaring a variable as
constant, as volatile. Operators and Expression.
UNIT - II
Decision Making and Branching: Decision making with If, simple IF, IF ELSE, nested IF ELSE, ELSE IF
ladder, switch, GOTO statement. Decision Making and Looping: While, Do While, For, Jumps in loops.
UNIT - III
Arrays: Declaration and accessing of one & two dimensional arrays, initializing two dimensional arrays,
multi-dimensional arrays.
UNIT - IV
Functions: The form of C functions, Return values and types, calling a function, categories of functions,
Nested functions, Recursion, functions with arrays, call by value, call by reference, storage classes –
character arrays and string functions
UNIT - V
Pointers: definition, declaring and initializing pointers, accessing a variable through address and through
pointer, pointer expressions, pointer increments and scale factor, pointers and arrays, pointers and functions,
pointers and structures.
Text Book
E.Balagurusamy, Programming in ANSI C, Fifth Edition, Tata Mc Graw- Hill, 2010.
Reference Books
Byron Gott fried, Schaum„s Outline Programming with C, Fourth Edition, Tata Mc Graw - Hill, 2018.
Kernighan and Ritchie, The C Programming Language, Second Edition, Prentice Hall, 1998
Yashavant Kanetkar, Let Us C, Eighteenth Edition, BPB Publications, 2021
Web Resources
1. https://codeforwin.org/
2. https://www.geeksforgeeks.org/c-programming-language/
3. http://en.cppreference.com/w/c
4. http://learn-c.org/
5. https://www.cprogramming.com
1
OVERVIEW OF C
INTRODUCTION
C is a Structured, High Level, Machine Independent Language.
C is a powerful, flexible and portable programming language.
C combines the features of High-Level Language with the elements of the Assembler.
It is suitable for both Systems and Applications programming.
It is most widely used general purpose language today.
1) WRITE ABOUT THE HISTORY OF C. (PART -B / C)
The root of all modern languages is ALGOL, introduced in the early 1960‟s.
C evolved from ALGOL, BCPL and B by Dennis Ritchie at the Bell Laboratories in 1972.
C uses many concepts from these languages and added the concept of data types and other powerful
features.
During 1970‟s, C had evolved into what is now
known as “Traditional C”.
The language becomes more popular after
publication of the book “The C Programming
Language” by Brian Kerningham and
Dennis Ritchie in 1978
To assure that C language remains standard, in
1983, American National Standards Institute
(ANSI) appointed a technical committee to
define a standard for C.
The committee approved a version of C in
December 1989 which is now known as ANSI
C.
It was then approved by the International Standards Organization (ISO) in 1990.
This version of C is also referred to as C89.
Although C++ and Java were evolved out of C, the Standardization Committee of C felt that a few
features of C++/Java, if added to C, would enhance the usefulness of the language.
The result was the 1999 standard for C and referred as C99.
IMPORTANCE OF C
2) DISCUSS THE IMPORTANCE OF C. (PART - B)
It is robust {strong} language to build program using Functions and Operator even to write any
complex program.
Program written in C are efficient and fast.
C support different data types and its powerful operators.
2
It is many times faster than BASIC (Beginners All purpose Symbolic Instruction Code) language.
During ANSI C period only 32 keywords were used.
It is well suited for structured programming so the user thinks of a problem in terms of functions and
blocks.
It has the feature / ability to extend itself.
The flexibility allows C to be used for system programming as well as for application programming.
A collection of functions that are supported by the C library.
It is possible to add our own functions in C library.
# Define Directive:
It is a Preprocessed Compiler Directive and not a statement.
#define is a preprocessor directive that is used to define macros in a C program.
#define is also known as a macros directive.
It helps us defines value to a symbolic constant for use in the program.
For Example:
#include <stdio.h>
#define PI 3.14
main() {
printf("%f", PI);
}
# Include Directive
Library functions in C are grouped category-wise and stored in different files known as Header Files.
To access those functions which is stored in the library using the compiler.
This is achieved by using the preprocessor directive #include as follows: #include <filename>
Void:
The keyword void means that the function does not return any information {value} to the operating
system.
Different methods for defining main( ) :
main( ) main(void)
int main( ) void main( void)
void main( ) int main(void)
Note:
int means that the function returns an integer value to the operating system.
SAMPLE C PROGRAM
/* Welcome to Vysya College */
#include<stdio.h>
#include<conio.h>
void main( )
3
{
printf( “ \n Welcome To C Programming “);
}
BASIC STRUCTURE OF C PROGRAMS:
3) DISCUSS THE BASIC STRUCTURE OF C PROGRAMS. (PART - B)
C program can be viewed as a group of building blocks called Functions.
A function is a subroutine that may include one or more statements.
It contain one or more sections as follows:
Documentation Section
It consists of a comment line giving the name of the program, author and other details.
Link Section
It provides instructions to compilers to link library files.
Definition Section
It contains symbolic constants.
Global declaration Section
It contains variable declaration
which can be accessed
anywhere within the program.
Main Section
It is divided into:
1) Declaration Part
2) Executable Part.
Declaration Part is used to
declare any variable that
can be accessed within
main block.
Executable Part contains
set of statements to be
executed.
Subprogram section
It contains a user-defined
function which tells the
function name, arguments and
return value.
4
EXECUTING „C‟ PROGRAM:
4) HOW TO EXECUTE A „C‟ PROGRAM (PART - B )
Executing a program written in C
involves a series of steps.
They are:
COMPILER IN C:
5
LINKING:
Linking is the process of putting together other program files and functions that are required by the
program.
The compiled and linked program is called the Executable Object Code.
Interpreter:
It is system software which is used to convert programming language code into binary format in step
by step process.
Assembler:
An assembler is system software which is used to convert the assembly language instruction into
binary format in step by step process.
DIFFERENCE BETWEEN COMPILER AND INTERPRETER
CHARACTER SET
6) WRITE THE CHARACTER SET IN C? (PART – B / C)
Data can be of any kind, it may be number of characters and strings
The characters in C are grouped into the following categories:
1) Letters:
Uppercase A…Z
Lowercase a…z
2) Digits: All decimal digits 0..9
3) Special characters:
SPECIAL CHARACTER
, (comma) { (opening curly bracket)
. (period) } (closing curly bracket)
; (semi-colon) [ (left bracket)
: (colon) ] (right bracket)
? (question mark) ( (opening left parenthesis)
„ (apostrophe) ) (closing right parenthesis)
! (exclamation mark) ^ (caret)
6
|(vertical bar) + (addition)
/ (forward slash) – (subtraction)
\ (backward slash) * (multiplication)
~ (tilde) / (division)
(greater than or closing
_ (underscore)
angle bracket)
< (less than or opening
$ (dollar sign)
angle bracket)
% (percentage sign) # (hash sign)
4) Trigraph Characters.
ANSI C introduces the concept of “trigraph” sequences to provide a way to enter certain
characters that are not available on some keyboards.
Each trigraph sequence consists of three characters (two question marks followed by another
character).
Trigraph Sequence Translation
??= # number sign
??( [ left bracket
??) ] right bracket
??< { left brace
??> } right brace
??! | vertical bar
??/ \ back slash
??- ~ tilde
C - TOKENS
7) EXPLAIN TOKENS IN C (PART – B / C)
8) WRITE ABOUT KEYWORDS AND IDENTIFIERS. (PART - B)
In a “C” program the smallest individual units are known as C Tokens.
C has six types of tokens.
7
KEYWORDS & IDENTIFIERS
KEYWORD:
IDENTIFIERS:
Identifiers refer to the names of variables, functions and arrays.
These are user-defined names and consist of a sequence of letters and digits, with a letter as a first
character.
Both uppercase and lowercase letters are permitted, although
lowercase letters are commonly used.
The underscore character is also permitted in identifiers.
It is usually used as a link between two words in long identifiers.
Rules for identifiers:
First character must be an alphabet (or underscore).
Must consist of only letters, digits or underscore.
Only first 31 characters are significant.
Cannot use a keyword.
Must not contain white space.
CONSTANTS
8
1) INTEGER CONSTANTS
An Integer Constant refers to a sequence of digits.
Types of Integers:
Decimal Integer
Octal Integer
Hexadecimal Integer.
Decimal Integer Constant
It consists of a set of digits, 0 through 9, preceded by an optional - or + sign.
For Example : 123 –321 0 654321 +78
Embedded spaces, commas, and non-digit characters are not permitted between digits.
Octal Integer Constant
It consists of any combination of digits from the set 0 through 7, with a leading 0.
For Example : 037 0 0435 0551
Hexadecimal Integer Constant
It consists of sequence of digits preceded by 0x or 0X.
They may also include alphabets A through F or a through f. The letter A through F represents the
numbers 10 through 15.
For Example: 0X2 0x9F 0Xbcd 0x.
2) REAL CONSTANTS
A real constant refers to a sequence of digits with decimal places.
For Example: 215. .95 -.71 +.5
A real number may also be expressed in exponential (or scientific) notation.
For Example:
215.65 may be written as 2.1565e2 in exponential notation.
e2 means multiply by 102.
Syntax :
Mantissa e exponent
The mantissa is either a real number expressed in decimal notation or an integer.
The exponent is an integer number with an optional plus or minus sign.
The letter e separating the mantissa and the exponent can be written in either lowercase or uppercase.
3) SINGLE CHARACTER CONSTANTS:
A single character constant (or simply character constant)
contains a single character enclosed within a pair of single
quote marks.
For Example: „5‟ „X‟ „;‟ „ ‟
9
The character constant „5‟ is not the same as the number 5.
The last constant is a blank space.
Character constants have integer values known as ASCII values.
For Example,
The statement printf (“%c”, „a‟);
It print the number 97,
It ASCII value of the letter a.
4) STRING CONSTANTS:
A string constant is a sequence of characters enclosed in double quotes.
The characters may be letters, numbers, special characters and blank space :
For Example:
“Hello!”
“1987”
“WELL DONE”
“?...!”
“5+3”
“X”
BACKSLASH CHARACTER CONSTANTS
C supports some special backslash character constants that are used in output functions.
These character combinations are known as escape sequences.
VARIABLES
10) WRITE ABOUT VARIABLES. (PART - B)
A variable is a data name that may be used to store a data value.
A variable may take different values at different times during execution.
A variable name can be chosen by the programmer in a meaningful way.
Variable names may consist of letter, digits, and the underscore (_) character.
Syntax:
Variable_name = value;
For Example:
int a;
a=100;
a - Name of the Variable
100 - Content of the variable
Rules for Assigning Name for a Variable:
We must begin with a letter.
Sometimes it allows underscore as the first character.
10
ANSI standard recognizes a length of 31 characters.
The variable length can‟t be more than eight characters, since only the first eight characters are treated
as significant by many compilers. (Note: In C99, 63 characters can be used.)
Uppercase and lowercase can be used.
White spaces are not allowed.
DATA TYPES
11) DISCUSS ABOUT DATA TYPES IN DETAIL. (PART – B / C)
ANSI C supports three classes of data types:
1) Primary (or Fundamental) Data Types
2) Derived Data Types
3) User-Defined Data Types
1) Primary or Fundamental Types:
Integer Types:
A double data type number uses 64 bits giving a precision of 14 digits; these are known as
Double Precision Numbers.
To extend the precision long double can be used which uses 80 bits.
11
Void Types:
The void type has no values. This is usually used to specify the type of functions.
The type of a function is said to be void when it does not return any value to the calling function.
Character Types:
A single character can be defined as a character (char) type data.
Characters are usually stored in 8 bits (one byte) of internal storage.
While unsigned chars have values between 0 and 255, signed chars have values from-128 to 127.
TABLE CHART : Size and Range of Data Types on a 16 Bit Machine
DECLARATION OF VARIABLES
12) HOW VARIABLES ARE DECLARED IN C. (PART - B)
Declaration does two things:
It tells the compiler what the variable name is.
It specifies what type of data the variable will hold.
Primary Type Declaration:
A variable can be used to store a value of any data
type.
Syntax : data-type v1,v2,….vn;
v1, v2,….vn are the names of variables.
Explanation:
Variables are separated by commas.
A declaration statement must end with a semicolon.
12
For Example :
int count;
User Defined Type Declaration:
C supports a feature known as “type definition” that allows users to define an identifier that would
represent an existing data type.
Syntax :
typedef type identifier;
type refers to an existing data type and “identifier” refers to the “new” name given to the
data type.
For Example:
typedef int units;
units batch1, batch2;
The compiler automatically assigns integer digits beginning with 0 to all the enumeration constants.
The automatic assignments can be overridden by assigning values explicitly to the enumeration
constants.
ASSIGNING VALUES TO VARIABLES
13) HOW TO INTIALIZE A VALUE TO VARIABLE? EXPLAIN. (PART - B)
Consider the following example :
int a,b,c;
scanf(“%d%d”,&a,&b);
c=a+b;
Here c is called the target variable.
13
While all the variables are declared for their type, the variables that are used in expressions (on the right
hand side of (=) sign) must be assigned values before they are encountered in the program.
ASSIGNMENT STATEMENT
Assigning a relevant value to a variable in a program is known as initialization or assignment.
Syntax:
Variable_name=constant;
For Example:
int year;
year=10;
year=year+1;
An assignment statement implies that the value of the variable in the right sides is assigned to left.
It means that the new value of year is equal to the old value of the year and also it adds one value.
It is possible to assign a value to variable during declaration.
Syntax:
data-type variable_name = constant;
For Example:
int year=10;
The process of giving initial value to a variable is called Initialization.
It also permits to initialize more than one variable as:
int p=q=s=0;
DECLARING A VARIABLE AS CONSTANT
To retain the certain variable name as constant during the execution of a program, use qualifier const as:
const int i=40;
DECLARING A VARIABLE AS VOLATILE
The volatile variables are changed at any time by other external program or by the same program.
volatile int b;
OPERATORS AND EXPRESSIONS
OPERATORS
An operator is a symbol that tells the computer to perform certain Mathematical or Logical
Computations.
TYPES OF OPERATORS:
14) DESCRIBE THE DIFFERENT TYPES OF OPERATORS AVAILABLE IN C. (PART - C)
C operators are classified as:
1) Arithmetic operators 4) Assignment operators
2) Relational operators 5) Increment and Decrement operators
3) Logical operators 6) Conditional operators
14
7) Bitwise operators 8) Special operators
1) ARITHMETIC OPERATORS
The arithmetic operator is a binary operator, which requires two operands to perform its operation of
arithmetic.
The arithmetic operators are as follows :
OPERATOR DESCRIPTION
+ Addition
- Subtraction
/ Division
* Multiplication
% Modulo or remainder
a) Integer Arithmetic:
When both the operands in a single arithmetic expression such as a+b are integers, the expression is
called an Integer Expression, and the operation is called Integer Arithmetic.
For Example :
a+b =15
a/b = 2
(a=10 & b=5)
Program:
main()
{ Input : Enter days : 364
int months, days; Output : Months=12 days Days=4
Input : Enter days : 45
Printf (“Enter days:\n”); Output : Months=1 Days days=15
Scanf (“%d”, &days);
Months=days/30;
Days=days%30;
Printf(:months=%d days=%d”, months, days);
}
b) Real Arithmetic:
An arithmetic operation involving only real operands is called Real Arithmetic.
A real operand may assume values either in decimal or exponential notation.
The operator % cannot be used with real operands.
c) Mixed-mode Arithmetic:
When one of the operands is real and the other is integer, the expression is called a Mixed-Mode
Arithmetic Expression.
15
If either operand is of the real type, then only the real operation is performed and the result is always
a real number.
For Example: 15 / 10.0 = 1.5
2) RELATIONAL OPERATORS
Relational operators compare between two operands and return in terms of true or false i.e. 1 or 0.
In C and many other languages a true value is denoted by the integer 1 and a false value is denoted by
the integer 0.
Relational operators are used in conjunction with logical operators and conditional and looping
statements.
== Equal to
!= Not equal to
The logical operators && and || are used when we want to test more than one condition and make
expressions.
For Example : a > b && x = = 10
An expression of this kind, which combines two or more relational expressions, is termed as a Logical
Expression or a Compound Relational Expression.
The logical expression given above is true only if a >b is true and x= =10 is true.
16
If either (or both) of them are false, the expression is false.
OPERATOR MEANING
&& Logical AND
|| Logical OR
! Logical NOT
Sample Program:
4) ASSIGNMENT OPERATORS:
Assignment operators are used to assign the result of an expression to a variable.
The most commonly used assignment operator is =.
Syntax:
Variable operand=expression;
For Example:
a=10;
a+=10;
The second type of assignment operator is a shorthand operator.
Instead of writing a=a+b, which can also be written as: a+=b;
STATEMENT WITH SIMPLE STATEMENT WITH
ASSIGNMENT OPERATOR SHORTHAND OPERATOR
a=a+1 a+=1
a=a-1 a-=1
a=a*(n+1) a*=n+1
a=a/(n+1) a/=n+1
a=a%b a%=b
Advantages:
What appears on the left hand side need not be repeated and therefore it becomes easier to write
The statement is more short and easier to read.
The statement is more efficient.
5) INCREMENT AND DECREMENT OPERATORS:
C allows two very useful operators not generally found in other languages.
17
These are the increment and decrement operators:
++ and - -
The operators ++ adds 1 to the operand, while - - subtracts 1.
Both are unary operators and takes the following form:
++m; or m++;
--m; or m--;
++m; is equivalent to m = m+1;(or m+= 1;)
--m; is equivalent to m = m-1;(or m-=1;)
RULES FOR ++ AND - - OPERATORS:
Increment and decrement operators are unary operators and they require variable as their
operands.
When postfix ++(or --) is used with a variable in an expression, the expression is evaluated first
using the original value of the variable and then the variable is incremented(or decremented) by
one.
When prefix ++(or --) is used in an expression, the variable is incremented(or decremented) first
and then the expression is evaluated using the new value of the variable.
The precedence and associatively of ++ and - - operators are the same as those of unary + and
unary -.
Sample Program:
main()
{
int d,a,c;
a=10;
c=++a;
a=10;
d=a++;
printf("\n\n\t\t A= %d\t C= %d",a,c);
printf("\n\n\t\t A= %d\t D= %d",a,d);
getch();
}
Output
A=11 C=11
A=11 D=10
6) CONDITIONAL OPERATORS:
A ternary operator pair “?:” is available in C to construct conditional expressions.
Syntax:
exp1 ? exp2:exp3
exp1,exp2 and exp3 are expressions
The operator ?: works as follows: exp1 is evaluated first.
18
If it is nonzero(true), then the expression exp2 is evaluated and becomes the value of the expression.
If exp1 is false, exp3 is evaluated and its value becomes the value of the expression.
For Example:
a = 10;
b = 15;
x = (a>b) ? a:b;
Sample Program
main()
{
int b,a,c;
a=10;
b=20;
c=(a>b)?a:b;
printf("\n\n \t\t C= %d", c);
getch();
}
Output :
C = 20
7) BITWISE OPERATORS:
C has a distinction of supporting special operators known as bitwise operators for manipulation of
data at bit level.
These operators are used for testing the bits, or shifting them right or left. Bitwise operators may not
be applied to float or double.
OPERATOR MEANING
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
<< Shift left
>> Shift right
19
For Example :
value=(x=10,y=5,x+y);
First assigns the value 10 to x, then assigns 5 to y,
Finally assigns 15 to value.
Applications of Comma Operator:
In For Loops : for (n=1,m=10,n<=m;n++,m++)
In While Loops : while (c=getchar(),c!=‟\0‟)
Exchanging Values : t=x;x=y,y=t;
SIZEOF OPERATOR:
Size of operator is used with operand and it returns the number of bytes the operand occupies.
For Example :
int m,k;
k=5;
m=sizeof(k);
printf(“%d”,m);
EXPRESSIONS
An expression is a combination of Variables, Constants and Operators.
All expressions result in some value that can be assigned to variables.
It is a sequence of operators and operands that reduces to a single value.
ARITHMETIC EXPRESSIONS
An arithmetic expression is a combination of variables, constants, and operators arranged as per the
syntax of the language.
EVALUATION OF EXPRESSIONS
15) HOW EXPRESSIONS ARE EVALUATED IN C? (PART – B / C)
Expressions are evaluated using an assignment statement of the form.
Syntax :
variable = expression;
variable is any valid C variable name.
When the statement is encountered, the expression is evaluated first and the result then replaces the
previous value of the variable on the left hand side.
All variables used in the expression must be assigned values before evaluation is attempted.
20
For Example:
x = a * b – c;
y = b / c * a;
z = a – b / c + d;
PRECEDENCE OF ARITHMETIC OPERATORS:
16) EXPLAIN THE PRECEDENCE OF ARITHMETIC OPERATORS. (PART- B)
An arithmetic expression without parentheses will be evaluated from left to right using the rules of
precedence of operators.
There are two distinct priority levels of arithmetic operators in C:
High priority * / %
Low priority + -
The basic evaluation procedure includes „two‟ left-to-right passes through the expression.
During the first pass, the high priority operators (if any) are applied as they are encountered.
During the second pass, the low priority operators (if any) are applied as they are encountered.
Consider the following evaluation statements that has been used in the program
x = a-b/3 + c*2-1
When a =9, b =12, and c = 3, the statement becomes
x = 9-12/3 + 3*2-1 and is evaluated as follows:
First pass
Step1: x = 9-4+3*2-1
Step2: x = 9-4+6-1
Second pass
Step3: x = 5+6-1
Step4: x = 11-1
Step5: x = 10
The order of evaluation can be changed by introducing parentheses into an expression.
17) LIST THE RULES FOR EVALUATION OF EXPRESSION. (PART- B)
1) First, parenthesized sub expression from left to right is evaluated.
2) If parentheses are nested, the evaluation begins with the innermost sub-expression.
3) The precedence rule is applied in determining the order of application of operators in evaluating
expressions.
4) The associativity rule is applied when two or more operators of the same precedence level appear in a
sub-expression.
5) Arithmetic expression is evaluated from left to right using the rules of precedence.
6) When parentheses are used, the expressions within parentheses assume highest priority.
21
TYPE CONVERSIONS IN EXPRESSIONS
18) DISCUSS THE DIFFERENT TYPES OF TYPE CONVERSION IN C. (PART – B / C)
19) LIST THE RULES OF TYPE CONVERSIONS IN C. (PART - B)
If the operands are of different types, the lower type is automatically converter to the higher type before
the operation proceeds is called Type conversion.
There are Two Types of Conversions:
1) Implicit Type Conversion
2) Explicit Type Conversion
1) Implicit or Automatic Type Conversion
C automatically converts any intermediate values to the proper type so that the expression can be
evaluated without losing any significance.
This automatic conversion is known as Implicit Type Conversion.
During evaluation, the lower type is automatically converted to higher type.
All short and char are automatically converted to int .
22
2) Explicit Conversion:
The process of local conversion of variables is known as explicit type conversion or casting a value.
Syntax:
(type-name) expression
type-name is one of the standard C data types
The expression may be a constant, variable or an expression.
EXAMPLE ACTION
x=(int)7.5 7.5 is converted to integer by truncation
a=(int)21.3/(int)4.5 Evaluated as 21/4 and the result would be 5.
b=(double)sum/n Division is done in floating point mode
y=(int)(a+b) The result of a+b is converted to integer
z=(int)a+b A is converted to integer and then added to b
p=cos((double)x) Converts x to double before using it
+ Unary plus
- Unary minus
++ Increment
-- Decrement
! Logical negation Right to left 2
~ Ones complement
* Pointer reference (indirection)
& Address
Sizeof(type) Size of an object/Type cast
23
* Multiplication
/ Division Left to right 3
% Modulus
+ Addition
Left to right 4
- Subtraction
<< Left shift
Left to right 5
>> Right shift
< Less than
<= Less than are equal to
Left to right 6
> Greater than
>= Greater than or equal to
== Equality Left to right 7
|= Inequality
& Bitwise AND Left to right 8
^ Bitwise XOR Left to right 9
| Bitwise OR Left to right 10
&& Logical AND Left to right 11
|| Logical OR Left to right 12
?: Conditional expression Right to left 13
=, * =. / =. %=. +=. Assignment operators
- =, &=,^=, | =, Right to left 14
<< =, >> =
, Comma operator Left to right 15
UNIT – I COMPLETED
Text Book
E. Balagurusamy, Programming in ANSI C, Fifth Edition, Tata Mc Graw- Hill, 2010.
POSSIBLE QUESTIONS
PART- A
1) A ____________translates a high-level language program into machine language.
a) Assembler c) CPU
b) Compiler d) Utilities
2) A (n) ________ provides access to system programs for editing, compiling, and so on.
a) Operating Systems c) PowerPoint
b) Spread sheet d) Access
3) Specify the correct order for these operations: execution, translation, linking, loading.
a) execution, translation, linking, loading
b) execution, translation, linking, loading
c) execution, translation, linking, loading
d) translation, linking, loading, execution
24
4) A high-level language program is saved on disk as a(n) ________ file.
a) Source file c) Target File
b) Binary file d) Executable File
5) Before linking, a machine language program is saved on disk as a(n) ________file.
a) Object File c) Target File
b) Binary file d) Source File
6) After linking, a machine language program is saved on disk as a(n) ________file.
a) Executable File c) Target File
b) Binary file d) Source File
7) A language is said to be _________ whenever the program is execute in the same operating system.
a) Platform Dependent c) Portable
b) Platform Independent d) None
8) ____________ Cannot be used as Variable Name
a) Keywords c) identifiers
b) tokens d) none
9) Every individual unit in a program is known as
a) tokens c) variables
b) constants d) none
10) Which of the following is not a valid C variable name?
a) int number c) int variable_count
b) float rate d) int $main;
11) _________is the process of putting other files and functions together, that are required by the
program
a) compiler c) Linker
b) Interpreter d) none
12) Which of the following is true for variable names in C?
a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length
13) Which of the following is not a valid variable name declaration?
a) int _a3 c) int 3_a
b) int a_3 d) int _3a
14) Which of the following is not a valid variable name declaration?
a) float PI = 3.14 c) int PI = 3.14
b) double PI = 3.14 d) #define PI 3.14
25
15) The format identifier „%i‟ is also used for _____ data type.
a) char c) float
b) int d) double
16) Which data type is most suitable for storing a number 65000 in a 32-bit system?
a) signed short c) long
b) unsigned short d) int
17) Which of the following is a User-defined data type?
a) typedef int Boolean;
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) struct {char name[10], int age};
d) all of the mentioned
18) What is the size of an int data type?
a) 4 Bytes c) Depends on the system/compiler
b) 8 Bytes d) Cannot be determined
19) Which is correct with respect to the size of the data types?
a) char > int > float c) char < int < double
b) int > char > float d) double > char > int
20) Which keyword is used to prevent any changes in the variable within a C program?
a) immutable c) const
b) mutable d) volatile
21) What will be the final value of x in the following C code? int x = 5 * 9 / 3 + 9
a) 3.75 c) 24
b) Depends on compiler d) 3
22) Which of the following is not an arithmetic operation?
a) a * = 10 c) a ! = 10
b) a / = 10 d) a % = 10;
23) What is the result of logical or relational expression in C?
24) a) True or False b) 0 or 1
c) 0 if an expression is false and any positive number if an expression is true
d) None of the mentioned
25) Which among the following is NOT a logical or relational operator?
a) != c) ||
b) = = d) =
26) user enters any blank spaces, tabs, and newlines?
a) consider as input c) produces error
b) ignores it d) nothing can be said
26
27) What error will generate if the read and write parameters are not separated by commas?
a) run-time error c) logical error
b) Compile error d) no error
28) Which type of conversion is NOT accepted?
a) From char to int c) From negative int to char
b) From float to char pointer d) From double to char
PART - B
27