Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

CHAPTER :STRINGS

Strinq Declaration
data-type aYrayiame Sizel haoa
Im the Case of stvingsthedata type 13
char and the Sizeofthe array should be
total number of charactersto be/stored
plus One One added lb store the
tevmination character (\o) for a str1n, which
suse viternally to identify the end
he Stmng

char str [ul e


Array Str can
Array Store a stnng o f
length 1o characters

Initializing a character arrayo


First way Of Initialization)tap
include k iostream.hy
4 include < conio.hy
Noid MaiiCOilitin oy
dtonaveis shulbvit
clrscr)
chay str L6]-{ ' h ' e ' ' o \ o
Coutak Str
Camlin
getchC) 1STC T aTTA

5econd Oay oFinittalizatfon ab


tinclude zias-treanm.h 30 u
#include < Conio.hys
Void Man C) o fsdovuu

i vdeclrscrC) o 0
char str Lo
str [ol-'h
Str[11- 'e
str]-T
ande Str 3]'L VATYA
Str 4] = 'otaula
Str [5] '1o
Cout kz/Str od o pisilsidi
getch C) osiloiii a i
1deoibwenit
oiwooablbali
Thivd ay of mitialtzationiunMioy
tinclude < iostream.h7
4+ include Conio. hz
oNotdMain ) lde
Camlinn
sdpvClrscr ()vbi vderornsb OpoY

char str [6]" hello aiiolhauu


Cout ak str
getchC 00deoia shuoni
K OiNO S6slo

PrograM lo accept a Stringand then


display i t
#include kiostreaM-h7 "
include Conio. h e
Vofd mau C) de01)
Clrscr C e
char Str [21
Cont a"Enter a string: dd
CIV 2 Str
Cowt k " 5tn1ng 1S str;
9etchC) j

wses oTeMIbdeni Output :


O98 bEntera Str1nq d Computer
os oJiten5tnn 15oasComputer w
Camlin
Progro
rogram to demonstvate fndividua
Manipulation Js
character

+include siostream.h
include < conio.hz
Votd MaiC)

drscYc)irte
char str 1o]
coutk Entera string : ai
CinyStr: oino
Tor Ci-o str[il-loitt)V
Cout k4 Str[i] 4k endl;
qetch 0Ne 1tnd NO

lo
To Store MOre than one string IM an
an
array declare two dimens ional chavacter
array Where the Strst dfmen.sion epYesents
theMumberOfStyings and the Second
dimensionrepresenls he length of each
sting
Camlin
tinclude ziostveaM.hy
include k conto.hz
Noid Mai C)

clrscrc)
char st[3][U
int i
tor CiO; is3 it
Cout az " Enter a stng:"
Cin Str [il

torCi=0; ik3 itt)


Cout4 Str[il kt

getch C)

Output
Enter a strfnq: Houo
mter a strine: a r e
Enter a sirt You
Hoo are you

Camlin

You might also like