You are on page 1of 19

CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

INTRODUCTION OF C LANGUAGE
INTRODUCTION OF COMPUTER LANGUAGES

 In all over the world, language is the source of communication among human beings.
 In all over the world, we have different languages according to regions / countries.
 To work with one another, we must need to know each other’s language then only we can
communicate properly.
 Likewise, to work with the computer, user (a person who are using / operating the computer) has
to know the language understood by the computer.
 For this purpose, different computer languages are developed to perform different types of work
on the computer.
 According to their work, pros and cons, the computer languages are classified in the following three
levels:
1. Low level language
2. High level language
3. Middle level language

1. Low level language


 The fundamental language of the computer’s processor, also called Machine Language.
 All programs are converted into machine language before they can be executed.
 It consists of combination of 0’s and 1’s that represent high and low electrical voltage.
 Low level languages are sometimes divided into two categories:
i. Machine Language – Also known as First Generation Language (1GL)
ii. Assembly Language – Also known as Second Generation Language (2GL)

Machine language (1GL)


i. It is also known as Binary Language in which the statement is combination of 1’s
and 0’s.
ii. The statement written in this language is directly understood by machine.
iii. Advantages of Machine Language
 It makes fast and efficient use of the computer.
 It requires no translator i.e. Directly understood by the computer
 Fast in program execution.
iv. Disadvantages of Machine Language
 All operation codes have to be remembered.
 All memory addresses have to be remembered.
 It is hard to amend or find errors in a program written in the machine
language.
 Machine Dependent i.e. a Particular - Machine language can be used on only
one type of computer
 Debugging process is difficult.

Page 1 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

Assembly language (2GL)


i. A low level language that is similar to machine language.
ii. Uses symbolic operation code to represent the machine operation code.
iii. Advantages
 It is easier to understand and use as compared to machine language.
 It is easy to locate and correct errors.
 It is modified easily.
iv. Disadvantages
 Like machine language it is also machine dependent.
 Since it is machine dependent therefore programmer should have the
knowledge of the hardware also.

2. High level language


i. High-level languages are basically symbolic languages that use English words and/or
mathematical symbols rather than mnemonic codes.
ii. Each instruction in the high level language is translated into many machine language
instructions thus showing one-to-many translation.
iii. Computer (programming) languages those are easier to learn.
iv. Uses English like statements.
v. Examples are C ++, Visual Basic, Pascal, Fortran etc.
vi. Advantages
 User-friendly
 Similar to English with vocabulary of words and symbols
 Therefore it is easier to learn.
 They require less time to write.
 They are easier to maintain.
 Problem oriented rather than 'machine' based.
 Program written in a high-level language can be translated into many machine
language and therefore can run on any computer for which there exists an
appropriate translator.
 It is independent of the machine on which it is used i.e. Programs developed in
high level language can be run on any Computer
vii. Disadvantages
 A high-level language has to be translated into the machine language by a
translator and thus a price in computer time is paid.
 The object code generated by a translator might be inefficient Compared to an
equivalent assembly language program.

3. Middle level language


i. In this category, program development is faster than low level but slower than high
level languages.
ii. C language is considered as a middle level language.
Page 2 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

INTRODUCTION OF PROGRAMMING CONCEPT

 Program / Software is required to help for growing business, academic or research work and other
factors.
 With the help of program/software we can complete our task fast and with accuracy.
 To solve any problem using program / software, we may require textual information – step by step
data (Known as ALGORITHM) as well as graphical view of information (Known as FLOWCHART).

INTRODUCTION OF C LANGUAGE (HISTORY & OVERVIEW)

 The basic goal was to create a language for writing operating systems. C was a mechanism for
providing portable assembly language.
 B was derived from BCPL, written in 1970 by Ken Thompson for the first UNIX system on the DEC
PDP-7.
 C has its origin in the early 1970s in Basic Combined Programming Language (BCPL), a project
shared by AT&T Bell Labs, USA, and developed by Martin Richards.
 Dennis Ritchie is credited with defining and creating C from the language B.
 C is closely related to the UNIX operating system since it was developed to be used in it.
 C language inherits the features of previous languages such as B and BCPL.
 In 1978, Brian Kernighan and Dennis Ritchie published the first edition of The C Programming
Language.
 This book, known to C programmers as "K&R", served for many years as an informal specification of
the language.
 The version of C that it describes is commonly referred to as K&R C.
 C was finally standardized in 1989, and was named ANSI C.

Timeline of Language Development

Year Language Developed By

1960 Algol International Group

1967 BCPL Martin Richards

1970 B Ken Thompson

1972 Traditional C Dennis Ritchie

1978 K&RC Kernighan & Ritchie

1989 ANSI C ANSI Committee

1990 ANSI / ISO C ISO Committee

1999 C99 Standardization Committee

Page 3 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

DIFFERENCE BETWEEN TRADITIONAL AND MODERN C


Points To
No. Traditional C Modern C
Remember

The Modern C is developed in year 1999. So, it


1 Development Early 1972.
can also known as C99.

2 Developer Developed By Dennis Ritchie. Developed By Standardization Committee.

3 Speed Very Slow Very High Speed

4 Features Very few features are exists. Very new features are added.

C99 New five keywords added. So, total 37


5 Keywords Only 32 Keywords.
keywords are in Modern C.

C PROGRAM STRUCTURE
C language program consists of following sections:
Documentation Section
Link Section
Definition Section
Global Declaration Section
main() function section
{
}
Subprogram Section (User Defined Function)
Function 1
Function 2

1. Document Section :
The documentation section consists of a set of comment lines giving program information.

2. Link Section :
The link section provides instruction to the compiler to link functions from the system library.

3. Definition Section :
The definition section defines all symbolic constants.

Page 4 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

4. Global Declaration Section :


There are some variables that are used in more than one function. Such variables are called global
variables and are declared in the global declaration section that is outside of all the functions.

5. Main() Section :
Every C program must have one main() function section.

6. Subprogram Section:
The subprogram section contains all the user defined functions that are called in the main function.

C CHARACTER SET
C language character set denotes any valid character in C programming language. This character can be
alphabet, digit, special symbols and white spaces. Following table shows the valid alphabets, numbers,
special symbols and white spaces allowed in C language.

Alphabet A, B, ……. , Z
a, b, …….., z
Digits 0, 1, 2, 3, ……, 9
Special Symbols , Comma
; Semi Colon
. dot (period)
/ slash
~ tilde
$ dollar sign
White spaces Blank Space
Horizontal Tab
Carriage Return
New Line
Form Feed

Page 5 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

Tokens
 Tokens are Language Elements or Language Building Blocks.
 Identifiers, operators, keywords, literals and special characters are example of tokens.
 Tokens can be used to build high level constructs like expression, statements.
C Tokens
Identifiers and Variables
Keywords
Literals and Constants
Strings
Operators
Special Symbols

Identifiers and Variables


 The identifier is only used to identify an entity uniquely in a program at the time of execution
whereas, a variable is a name given to a memory location that is used to hold a value.
 Variable is only a kind of identifier, other kinds of identifiers are function names, class names,
structure names etc.
 In other words, the name of variables, functions or arrays in a program is called an Identifier.
A variable is a data name that may be used to store a data value.
 Unlike constants that remain unchanged during the execution of a program, a variable may take
different values at different times during execution.
 Identifier (variable) naming rules:
o The first character in the variable name must be letter.
o Identifier length is maximum 31 characters.
o Keywords are not allowed as an identifier.
o No commas or blanks are allowed within a variable name.
o No special symbol except underscore (as in gross_sal) can be used in a variable name.
 Some examples of valid variable names are: john, Delhi, x1, Value, T_raise, sum1
 Some examples of invalid variable names are: 123, (area), x-y, %, 25th

Keywords
 Reserved identifiers used by the language.
Auto Break Case Char
Const continue Default Do
Double Else Enum extern
Float For Goto If
Int Long Register return
Short signed Sizeof static
Struct switch Typedef union
Unsigned Void Volatile while

Page 6 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

Literals and Constants


 A literal is a value that is expressed as itself. For example, the number 25 or the string “Hello”
are both literals. Whereas a constant is a data type that substitutes a literal.
 Constants in C refer to fixed values that do not change during the execution of a program.
 C supports several types of constants as under:

CONSTANTS

NUMERIC CHARACTER
CONSTANTS CONSTANTS

INTEGER REAL STRING SINGLE CHARACTER


CONSTANTS CONSTANTS CONSTANTS CONSTANTS

Integer Constants
 An integer constant refers to a sequence of digits.
 Decimal integers consist of a set of digits, 0 to 9, preceded by an optional – or + sign.
 Valid examples of decimal integer constants are:
123, -321, 0, 456, +78.
Real Constants
 Real Constants are numerical values with fractional part.
 Valid examples of real constants are:
215.50, .98, .60, 456.89, +85.90, -0.80.
Single Character Constants
 A single character constant contains a single character enclosed within a pair of single quote
marks.
 Examples of character constants are:
‘5’, ‘A’, ‘X’, ‘x’.
String Constants
 A String constant is a sequence of characters enclosed in double quotes.
 The string may contain letters, numbers, special characters and blank space.
 Examples are:
“Hello!”, “1987”, “Wel Come”, “?....!”, “ 5+3 “

String
 As above specified, string is a sequence of characters enclosed in double quotes.
 C language does not support String data type.
 We can use String in C language with the help of an Array.
 In double quotes we can have anything like alphanumeric, digits, symbols etc.

Page 7 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

Operators
 Followings are different classifications for C language Operators:

Arithmetic Operators +, -, *, /. %
Relational Operators <, <=, >, >=, ==, !=
Logical Operators !, &&, ||
Ternary Operator (Conditional Operator) ?:
Bitwise Operators <<, >>
Assignment Operator =
Comparison Operator ==
Unary Operators +, -, ++, --

Arithmetic Operators
 There are five arithmetic operators in C language.

Operators Description Example Result Precedence


Multiplication of n1
* Multiplication n1 * n2 1
and n2
/ Division n1 / n2 Division of n1 and n2 1
% Modulus n1 % n2 Modulus of n1 and n2 1
+ Addition n1 + n2 Addition of n1 and n2 2
Subtraction of n1 and
- Subtraction n1 – n2 2
n2

 Multiplication, Division and Modulus operator’s priority is higher than Addition and
Subtraction operator. So, if in any arithmetic statement these operators are available
then Multiplication, Division and Modulus Operation is performed first. After that
Addition and Subtraction is performed.

o Relational Operators
 There are six relational operators in C language.
Operators Description Example Result
< Less Than n1 < n2 true if value of n1 is less than n2
true if value of n1 is less than or
<= Less Than equal to n1 <= n2
equal to n2
> Greater Than n1 > n2 true if value of n1 is greater than n2
true if value of n1 is greater than or
>= Greater Than equal to n1 >= n2
equal to n2
== Equality n1 == n2 true if n1 and n2 are equal
!= Inequality n1 != n2 true if n1 and n2 are not equal

Page 8 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

 Relational operators are useful in relational conditions (i.e. decision making and looping
structures).
 Relational operators are binary operators and require two operands.
 Relational operator returns result of operation either true (1 or other than 0) or false.

o Logical Operators
 There are three logical operators in C language.
 Logical Operators are use to give multiple relations conditions.

Operators Description Example Result


! Logical NOT ! n1 returns true if n1 is false
returns true only if both conditions
&& Logical AND n1 > 0 && n1 <= 100
are true
returns true if any one condition is
|| Logical OR n1 == n2 || n1 == n3
true

o Ternary Operators (Conditional Operator):


 The Conditional operator ? and : are sometimes called ternary operators because they
take three arguments. Ternary operator can be used instead of if…else condition.
 Syntax:
Expression1 ? expression2 : expression3
OR
Condition ? true part : false part
 Expression1 Relational Condition
 Expression2 if relational condition in expression1 is true, the value
returned will be expression2
 Expression3 if relational condition in expression1 is false, the value
returned will be expression2
 Example:
int x, y;
scanf(“%d”, &x);
y = (x > 5 ? 3 : 4);
This statement will store 3 in y if x is greater than 5, otherwise it will store 4 in y. the
equivalent if statement will be:

if (x > y)
y = 3;
else
y =4;

Page 9 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

o Bitwise Operators
 They work on bits and perform bit by bit operation.

Operators Description Example


& Bitwise-AND A&B
| Bitwise-inclusive-OR A|B
^ Bitwise-exclusive-OR A^B
<< Bitwise - Left Shift A << 2
>> Bitwise-Right Shift A >> 2

 For example, if we have A = 60 and B = 13 then,


 Binary Format of A and B are : A = 0011 1100,
B = 0000 1101
 A & B = 0000 1100
 A | B = 0011 1101
 A ^ B = 0011 0001
 ~A = 1100 0011

o Assignment Operator (=)


 This operator is used to assign a value to the variable / constant.
 In C language expression, the right part of assignment operator will be assigned to left
part.
 For Example: a = 5 or a = b + c.

o Comparison Operator (==)


 The two times equal to sign (‘ == ‘) is used to compare two variables / constants / values.
 Mostly comparison operator is used with decision statement (if condition).
 For Example: if (a == b) – This will check / compare the values of a and b.

o Unary Increment and Decrement Operators (++, --)


 Unary Increment and Decrement operator can work as follows:
 Pre increment
 Post increment
 Pre decrement
 Post decrement
 When increment operator works as a pre increment operator, the operand value is
increased by one before any assignment.
 When increment operator works as a post increment operator, the operand value is
increased by one after any assignment.
 When decrement operator works as a pre decrement operator, the operand value is
decreased by one before any assignment.
Page 10 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

 When decrement operator works as a post decrement operator, the operand value is
decreased by one after any assignment.

Special Symbols
 C language supports special symbols in the program. Some of them are as under:
# Before pre-processor directives
{ When program / block starts
} When program / block ends
; To terminate program statements

Hierarchy of Operators:
Operator Description Associativity Rank
() Function Call
L To R 1
[] Array Element reference
+ Unary Plus
- Unary Minus
++ Increment
-- Decrement
! Logical Negation
R To L 2
~ One’s Complement
* Pointer reference
Sizeof size of an object
& Address
(type) Type Conversion (case)
* Multiplication
/ Division L To R 3
% Modulus
+ Addition
L To R 4
- Substraction
<< Left Shift
L To R 5
>> Right Shift
< Less Than
<= Less Than Or Equal To
L To R 6
> Greater Than
>= Greater Than Or Equal To
== Equality
L To R 7
!= Inequality
& Bitwise AND L To R 8
^ Bitwise XOR L To R 9
| Bitwise OR L To R 10
&& Logical AND L To R 11
Page 11 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

|| Logical OR L To R 12
?: Conditional Expression R To L 13
= *= Assignment Operators
/= %=
+= -=
R To L 14
&= ^=
|= <<=
>>=

C LANGUAGE DATA TYPES

PRIMARY DATA TYPES

Integral Data Types CHARACTER

Signed Unsigned

int unsigned int char


short int unsigned short int signed char
long unsigned long unsigned char

Floating Point Type


void
float double long double

Type Length Range


Char 8 bits -128 to 127
signed char 8 bits -128 to 127
unsigned char 8 bits 0 to 255

Int 16 bits -32768 to 32767


signed int 16 bits -32768 to 32767
unsigned int 16 bits 0 to 65535
signed short int 8 bits -128 to 127
unsigned short int 8 bits 0 to 255

Long 32 bits -2147483648 to 2147483647


signed long 32 bits -2147483648 to 2147483647
unsigned long 32 bits 0 to 4294967295

Float 32 bits 3.4 * 10-38 to 3.4 * 10 +38


Double 64 bits 1.7 * 10-308 to 1.7 * 10 +308
long double 80 bits 3.4 * 10-4932 to 3.4 * 10 +4932
Page 12 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

TYPE CASTING
 Any mathematical operation requires same data type of operands.
 In mathematical expression, various data types of operands are used. In this situation expression
cannot be evaluated.
 Type casting refers to changing a variable of one data type into another.
 In C Language, there are two ways to change type of variable from one data type to another:
Automatic and Manual.
 The Automatic process is known as Type Conversion which is done by compiler itself.
 The Manual process is known as Type Casting which is done explicitly by the programmer.
 If lower data type is converted to higher data type, this is known as type promotion.
 If higher data type is converted to lower data type, this is known as type demotion.

int i, x;
float f;
double d;
long l;

Preprocessor Directives:
 Preprocessor is one of the important features of C Language.
 It makes program easy to read, easy to modify and more efficient.
 As the name, it processes the source code before it passes through the compiler.
 The preprocessor is the separate step in the compilation process.
 The preprocessor directives operate under the control of preprocessor command line or
directives.
 The preprocessor directives are placed before the main().
 Every preprocessor begins with # and does not require semicolon at end.
 Steps of execution...
Source Code => Preprocessor => Expanded Source Code =>
Compiler => Object Code => Linker => Executable Code
Page 13 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

 The preprocessor converts the source code into the expanded source code, then it is
compiled by the compiler to convert it into the object code and the linker then converts this
into executable code.
 The preprocessor is used with source code in 3 ways:
o File Inclusion:
 Inserting the contents of another file into source file.
 The directive #include "file name" is used to include any file in program.
 The #include instructs to read entire file.
 Generally used with header files.
 Syntax:#include <filename> OR #include "filename"
 The difference between the using of < > and " " is, If the file enclosed with <
>, then the search will be done in standard directories where the libraries are
stored. And in case of " ", search will be done in current directory or
directory containing the source file.
 Example: #include<stdio.h> OR #include "stdio.h"

o Macro Substitution:
 In macro substitution an identifier in a program is replaced with predefined
string.
 Followings are different forms of macro substitution:
 Simple Macro Substitution:
o In this #define is used.
o For Ex: #define pi 3.1415

 Macros as Arguments:
o The preprocessors also have arguments as follow:
o Ex: #define area(r) (3.14 * r * r)
 Nesting of Macros:
o We can also have one macro in the definition of another
macro. That means Nested Macro.
o Ex: #define SQUARE(x) (x*x) OR
#define CUBE(x) (SQUARE(x) * x)

o Conditional Compilation Directive:


 Followings are different conditional directives:
 #ifdef - Tests for macro definition
 #endif - Specify the end of if
 #ifndef - Test whether the macro is not defined
 #if - Test the compile time condition
 #else - The alternative condition when #if test fails

Page 14 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

SYMBOLIC CONSTANT:
 Symbolic constant is a name that substitutes for a sequence of characters or numeric constant, a
character constant or a string constant.
 When a program is compiled each occurrence of a symbolic constant is replaced by its
corresponding character sequence.
 Syntax:
#define symbolic_name value_of_constant
Where,
#define = Preprocessor Directive
symbolic_name = Name of Constant
value_of_constant = Value of Constant
 Example: #define MAX 100
 Here, the # character is used for preprocessor commands. A Preprocessor is a system program,
which comes into action prior to compiler, and it replaces the replacement text by the actual text.

 Advantages:
o They can be used to assign names to values.
o Replacement of value has to be done at one place.
 Rules:
o Symbolic names have same form as variable name.
o To distinguish them, we can use them in capital letters.
o # sign must be first character in statement
o No space is permitted between # and define
o It does not terminate with a semicolon sign.
o Symbolic names are not declared for data types.
o Once a value is assigned to symbolic constant, we cannot set new value for that variable.
o We can use #define statement anywhere in the program.

 Invalid #define statements:


#define s=10;
#define a 10,b 15
#Define aa 10
# define $a 11

INTRODUCTION OF LOGIC DEVELOPMENT TOOLS

INTRODUCTION OF LOGIC:
 Logic is a statements / instructions for solving any problem simply.
 Any complex program / problem solution requires arithmetic – logical operations.
 User can solve problem using simple / complex logic.

Page 15 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

NECESSARY INSTRUCTIONS FOR DEVELOPING LOGIC:


 The best practice of logic development is on paper work of any complex program solution.
 To find the solution of any program:
o First of all think about the different methods / techniques to solve this.
o Select best and convenient method to solve the problem.
o Make a list of identifiers required for the solution.
o Think about input and output for the problem.
o Think about arithmetic and logical statement required to solve the problem.
o Display the result that user wants.

Introduction of Algorithm
 Algorithm can be defined as:
o It is a set of step-by-step instructions to execute the code.
o It is a part of computer program for solving a particular problem using a number of steps in
specific order.
o It is a step-by-step explanation of solution.
o It is a finite set of instructions to solve the problem.
 To write an algorithm we must follow step-by-step method and for that different keywords are
used.
 For Example: Begin / Start, End / Stop, Read / Input, Write / Output etc.
 Features of Algorithm
o Specific Order
o Checking Conditions
o Repeat Statements
o Finite number of steps

 Advantages of Algorithm
o A programmer can know identification of the processes, major decision statements and
required variables for solving the problem in the development time.
o It provides entire solution of problem in textual format.
o As step-by-step information is there in algorithm, then debugging is easy.
o Writing an algorithm is an easy as it is in regular English language like statements only.

Introduction of Flowchart
 Flowchart can be defined as:
o It is a graphical or symbolic representation of a process of problem solution.
o Flowchart is pictorial representation of a problem with different shapes and in step by step
manner.

 Symbols of Flowchart:
o Terminal Symbol: Used to represent start (begin) or stop (end) the process in flowchart.

o Parallelograms/ I/O Symbol: Used to get input or display output to the users. It is also
known as Data Shape.

Page 16 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

o Process: Used to show the process or arithmetic operation required for problem solution.

o Decision / Conditional / Diamond Shape: Used to show the process or arithmetic operation
required for problem solution.

o Connector: Used as a flow of process or jump from one point to another. Connectors are
labeled as A, B, C…. Mostly they are used to connect two or more pages.

o Arrow / Flow Line: Used to connect two symbols. It shows the direction / flow of process.

 Advantages of Flowchart
o A graphical representation of any process is easy to understand than the textual
information. So, flowchart can be good interface for communication.
o The problem solution can be analyzed easily with the help of flowchart.
o As in this, our problem is represented with various symbols; it is required to debug the code
or to solve the error.

 Disadvantages of Flowchart
o Drawing a flowchart becomes very difficult when we have complex logic (problem).
o The modification in flowchart is difficult.
o This is used only for those who know the meaning of flowchart symbols.

Dry-Run and its use


 Dry-run is a step-by-step testing process of problem which gives the latest value of variable and
output of specific statement.
 For dry-run we don’t require any compiler.
 It is an execution of program with dummy value and gets the output of each statement.
 Dry-run is useful as through this programmer can know actual output of the statement or error in
the program.
 Dry-run is used to check each statement logically and syntactically.
 Mostly it is useful while we have iterative statements in our program.

Other Logic Development Techniques


 Followings are various technique used to develop program logic:
o Implement Modular Programming – that is, using UDF.
o Use step-by-step debugging to analyze problem.
o Prepare pseudo code according to definition.
Page 17 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

Comments
 The C language supports two kinds of comments:
o Multi-line Comment : /* text */
o Single-line Comment : // text
 The compiler ignores everything from // to the end of the line.

ASSIGNMENT – I

Fill in the blanks:


1. ______________ and ____________ are comments in C language.
2. ______ functions starts C program execution.
3. 1234 is an example of ________ constant.
4. “A” is an example of ________ constant.
5. ‘A’ is an example of __________ constant.
6. Full form of ASCII is ____________________.
7. Range of char data type is __________ to _____________.
8. _______ is the largest data type in C language.
9. Type casting is also known as ___________.
10. Result of relational condition is either _______ or ________.
11. Expression 15 % 4 % 4 return __________ as result.
12. Every C statement ends with __________.
13. Variable name must begin with _________.
14. The operator _______ cannot be used with real operands.
15. C supports as many as _________ relational operators.
16. The ________ operator returns the number of bytes the operand occupies.
17. _________ is used to determine the order in which different operators in an expression are
evaluated.

True / False:
1. Literals and constants are same.
2. Character constants can store one character.
3. String constants can store more than one character.
4. The main is a keyword in C language.
5. The keyword can be used as variable name.
6. Use of comments reduces the speed of execution of a program.
7. A printf statement can generate only one line of output.
8. Floating point constants, by default denote float data type.
9. The expression x >= y is same as x < y
10. The statement a = +10 is valid.
11. The expression a + 4 / 6 * 6 / 2 evaluates to 11.

State the output of following expressions. Assume the value a, b, and c is 10, 20 and 5 respectively.
Page 18 of 19
CS – 02 Problem Solving Methodologies And Programming In C Unit - 01

1) a+2%5+b+c 8) 1.0 / 3 15) 3 * 4 * 5 / (6 * 2) / (2 + 1)


2) a*b+c 9) 1.0 / 3.0 16) a % b % c
3) a+b*c 10) a * b / c 17) a % (b % 2)
4) a+b+c*c 11) a / b * c 18) (a + b) % (3 + 3)
5) (a + b + c) * c 12) a / (b * c) 19) a + (b % 3) + 3
6) 1/3 13) 2 + 3 + 4 % 5 % 6 + 7 20) a + b % 3 + 3
7) 2/3 14) 4 + 5 * 6 + (7 / 2) 21) a +=b

Page 19 of 19

You might also like