100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Lecture notes

Computer system

Rating
-
Sold
-
Pages
20
Uploaded on
24-07-2023
Written in
2017/2018

Computer system, computer science, computer skills, computer language,











Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
July 24, 2023
Number of pages
20
Written in
2017/2018
Type
Lecture notes
Professor(s)
Prof
Contains
All classes

Subjects

Content preview

Enter 12 values:

123456789101112

Displaying Values:

test[0][0][0] = 1

test[0][0][1] = 2

test[0][1][0] = 3

test[0][1][1] = 4

test[0][2][0] = 5

test[0][2][1] = 6

test[1][0][0] = 7

test[1][0][1] = 8

test[1][1][0] = 9

test[1][1][1] = 10

test[1][2][0] = 11

test[1][2][1] = 12




STRINGS:
String Concepts

String is an array of characters that is terminated by \0 (null character). This null
character indicates the end of the string. Strings are always enclosed by double quotes ( "
" ). Whereas, character is enclosed by single quotes.

Or



C PROGRAMMING Page 111

, In „C‟ language the group of characters, digits, and symbols enclosed within double
quotation ( " " ) marks are called as string otherwise a string is an array of characters and
terminated by NULL character which is denoted by the escape sequence „\0‟.

C Strings

Declaration of String: C does not support string as a data type. However, it allows us to
represent strings as character arrays. In C, a string variable is any valid C variable name and it is
always declared as an array of characters.

The general form of declaration of a string variable is :

Syntax: char string_name[size];

The size determines the number of characters in the string name.

Note: In declaration of string size must be required to mention otherwise it gives an error.

Ex: char str[]; // Invalid

char str[0]; // Invalid

char str[-1]; // Invalid

char str[10]; // Valid

char a[9]; //Valid

Using this declaration the compiler allocates 9 memory locations for the variable a
ranging from 0 to 8.



0 1 2 3 4 5 6 7 8




Here, the string variable a can hold maximum of 9 characters including NULL(\0)
character.

Initializing Array string

Syntax : char string_name[size]={“string” };

Note: In Initialization of the string if the specific number of character is not initialized it then
rest of all character will be initialized with NULL.

C PROGRAMMING Page 112

, char str[5]={'5','+','A'};

str[0]; ---> 5

str[1]; ---> +

str[2]; ---> A

str[3]; ---> NULL

str[4]; ---> NULL

Note: In initialization of the string we can not initialized more than size of string elements.

Ex:

char str[2]={'5','+','A','B'}; // Invalid

Different ways of initialization can be done in various ways :

1 : Initilizing locations character by character.

2 : Partial array initialization.

3 : Intilization without size.

4 : Array initialization with a string .

1 : Initilizing locations character by character

Consider the following declaration with initialization,

Char b[9]={„C‟,‟O‟,‟M‟,‟P‟,‟U‟,‟T‟,‟E‟,‟R‟};

The compiler allocates 9 memory locations ranging from 0 to 8 and these locations are
initialized with the characters in the order specified. The remaining locations are automatically
initialized to null characters.



C O M P U T E R \0

0 1 2 3 4 5 6 7 8



2 : Partial Array Initilization : If the characters to be initialized is less than the size of the
array, then the characters are stored sequentially from left to right.The remaining locations will
be initialized to NULL characters automatically.
C PROGRAMMING Page 113
£16.29
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
akhilagouri

Get to know the seller

Seller avatar
akhilagouri A Level Notes
View profile
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
2 year
Number of followers
0
Documents
107
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions