Sei sulla pagina 1di 86

1

2
3
4
5
6
D
ER/CORP/CRS/LA06/003 7
8
The concept of string is available in the high level languages , though they may be available
in different forms . In C language, it is treated like an array, in Java it is in the form of
objects. This concept would be dealt during OOP module.
9
.
10
A group of characters (Alphabets, digits and special characters) is called as a string. For
example in order to store the name of a person or to store the name of an itema string have
to be used. In computing applications where processing of textual data are involved, strings
are useful in representing these textual data. When strings are written it is important that
they are enclosed with in double quotes. If a single quote is used it is treated as character
constants. For example M is different from M. The former one is called as a character
constant and the latter is called as string constant.
Each and every string ends with a null character \0. This designates the end of the string.
This \0 is a single character. So when it has to be explicitly assigned to a string, it has to be
written with in single quotes as \0. When the size of the string is decided, \0 should also be
considered. For example if the Department Name has at most 15 characters the size of the
string should be 15+1 which is 16.
11
12
The arrays can be initialized to string constants only during declaration. It is
in valid to write the assignment acItemCategory=Fruits; To assign the
value to the string, string function strcpy should be used. This will be dealt in
next session.
13
14
15
16
17
The null character \0 has so much of importance with respect to strings.
The built in string functions considers the characters in the string only till the
first null character is encountered. So, if an array contains the string Easy
to\0 go\0 then, only Easy to is considered by the string functions.
18
19
20
21
22
Answers:
1. (b) and (d) are Valid string declaration and initialization
(a) is Invalid because the string is enclosed in single quotes
(c) is invalid because in character by character initialization, it is the programmers responsibility to
assign the null char explicitly
2. Info
because the character following Info is a null character, therefore it is treated as end of the string
3. GGG
ooo
ddd
23
1. The condition expression in the if part present in the inner for loop of the bubble sort program needs to be
changed to :
if(aiNumbers[iIndex2]<aiNumbers[iIndex2+1])
2. Divide and Conquer approach
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
You may replace the individual scanf or gets statements with a single for
loop
42
Although the comparison is drawn for an integer array vs. string, this can
hold true for any non-character datatype array vs. string. This is done for
purpose of understanding the concept of string better.
43
44
45
46
47
Answer:
1. VALID: (iii)
INVALID: (I) and (ii) First argument of strcpy() function must be an array/pointer to hold the
string
2. VALID: (II) and (iii)
INVALID: (I) In the first argument, There should be enough memory to hold the combined
string after concatenation, this type of
statement may give runtime error/displays invalid result
3. Answer is 5 because wherever the \0 char is encountered first in the string, that is treated
as the end of the string and therefore strlen() function returns the number of characters
excluding first \0 character in the initialized string
48
49
50
Intermediate code generation may belong to either front end or back end
depending on the design chosen
51
52
53
In this compilation approach, the source code needs to be recompiled on
each platform. Thus the source code is portable provided it is recompiled on
the specific platform
54
In this compilation approach, the source code is written once and can be run
anywhere. The source code is compiled and results in an abstract
intermediate code which is then converted to specific machine code by the
back-end part of the compiler
55
In this compilation approach, the family of highlevel languages generate a
common intermediate code. There is a common backend compiler which is
specific to machine/platform which converts the intermediate code to specific
machine level code
Functional requirement defines the actual functionality of a software.
Some of the non functional requirements are :
Availability
Scalability
Security
Response time
Reliability
Effectiveness
Efficiency
Quality
Robustness etc..
While developing a solution to a given problem specification, along with providing a solution
to the problem we also need to ensure that the provided solution is efficient in terms of
performance by meeting its non functional requirements
57
58
59
60
Type conversions though done by the compiler are a costly overhead which
can be avoided where ever possible, by the programmers.
61
62
63
Jamming of loops can be applied to other similar examples like finding the
maximum and minimum, from a given set of elements, in one loop. In the above
example, we have highlighted the fact that boundary checks in a loop are
expensive. Loops which operate over different ranges cannot be jammed. We could
face problems with jamming of loops if at a later stage the range for two jammed
loops change!
The amount of savings in this technique is less, as loop checking wont require
much resources .
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
The objects and the binding concepts are discussed later in OOP course
85
The objects and the binding concepts are discussed later in OOP course

Potrebbero piacerti anche