0% found this document useful (0 votes)
9 views

07 Ascii Strintro en

Uploaded by

aryalrosn0655
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

07 Ascii Strintro en

Uploaded by

aryalrosn0655
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 51

Imperative programming

School of Technology and Management


The ASCII table
Strings introduction

[email protected]

STM

[email protected] (STM) Imperative programming 1 / 10


Summary

1 The ASCII table

2 Strings (introduction)

[email protected] (STM) Imperative programming 2 / 10


The ASCII table

Summary

1 The ASCII table

2 Strings (introduction)

[email protected] (STM) Imperative programming 3 / 10


The ASCII table

The ASCII table

Character Encoding → way to represent text in:


Computers
Telecommunication Equipment
Devices in general
ASCII (American Standard Code for Information Interchange)
is a Character Encoding
It’s also the base of most of the current Character Encodings (UTF-8,
Windows-1252, ISO-8859-*, . . . )
Number code for representing characters each character is
assigned a number
The original ASCII table was encoded with a 7-bit code
Consists of a 127 character-map codes from 0 to 127 (27 − 1 = 127)

[email protected] (STM) Imperative programming 4 / 10


The ASCII table

The ASCII table

Character Encoding → way to represent text in:


Computers
Telecommunication Equipment
Devices in general
ASCII (American Standard Code for Information Interchange)
is a Character Encoding
It’s also the base of most of the current Character Encodings (UTF-8,
Windows-1252, ISO-8859-*, . . . )
Number code for representing characters each character is
assigned a number
The original ASCII table was encoded with a 7-bit code
Consists of a 127 character-map codes from 0 to 127 (27 − 1 = 127)

[email protected] (STM) Imperative programming 4 / 10


The ASCII table

The ASCII table

Character Encoding → way to represent text in:


Computers
Telecommunication Equipment
Devices in general
ASCII (American Standard Code for Information Interchange)
is a Character Encoding
It’s also the base of most of the current Character Encodings (UTF-8,
Windows-1252, ISO-8859-*, . . . )
Number code for representing characters each character is
assigned a number
The original ASCII table was encoded with a 7-bit code
Consists of a 127 character-map codes from 0 to 127 (27 − 1 = 127)

[email protected] (STM) Imperative programming 4 / 10


The ASCII table

The ASCII table

Character Encoding → way to represent text in:


Computers
Telecommunication Equipment
Devices in general
ASCII (American Standard Code for Information Interchange)
is a Character Encoding
It’s also the base of most of the current Character Encodings (UTF-8,
Windows-1252, ISO-8859-*, . . . )
Number code for representing characters each character is
assigned a number
The original ASCII table was encoded with a 7-bit code
Consists of a 127 character-map codes from 0 to 127 (27 − 1 = 127)

[email protected] (STM) Imperative programming 4 / 10


The ASCII table

The ASCII table

Character Encoding → way to represent text in:


Computers
Telecommunication Equipment
Devices in general
ASCII (American Standard Code for Information Interchange)
is a Character Encoding
It’s also the base of most of the current Character Encodings (UTF-8,
Windows-1252, ISO-8859-*, . . . )
Number code for representing characters each character is
assigned a number
The original ASCII table was encoded with a 7-bit code
Consists of a 127 character-map codes from 0 to 127 (27 − 1 = 127)

[email protected] (STM) Imperative programming 4 / 10


The ASCII table

The ASCII table

Character Encoding → way to represent text in:


Computers
Telecommunication Equipment
Devices in general
ASCII (American Standard Code for Information Interchange)
is a Character Encoding
It’s also the base of most of the current Character Encodings (UTF-8,
Windows-1252, ISO-8859-*, . . . )
Number code for representing characters each character is
assigned a number
The original ASCII table was encoded with a 7-bit code
Consists of a 127 character-map codes from 0 to 127 (27 − 1 = 127)

[email protected] (STM) Imperative programming 4 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

We can separate the ASCII table in two main groups of characters:


Control Characters first 32 codes (0 31)
Printable Characters the remaining codes (≥ 32)
Control Characters → used to control the device behavior and
provide additional information:
[10] \n → line feed
[09] \t → horizontal tab
...
Printable characters include:
Numeric Digits
Alphabetic Characters
Punctuation

[email protected] (STM) Imperative programming 5 / 10


The ASCII table

The ASCII table

Control Characters,

NULL SOM EOA EOM EOT WRU RU BELL FE0 HT LF VTAB FF CR SO SI


0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

DC0 DC1 DC2 DC3 DC4 ERR SYNC LEM S0 S1 S2 S3 S4 S5 S6 S7


16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

DEL
127

[email protected] (STM) Imperative programming 6 / 10


The ASCII table

The ASCII table

Control Characters, Numeric Digits,

NULL SOM EOA EOM EOT WRU RU BELL FE0 HT LF VTAB FF CR SO SI


0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

DC0 DC1 DC2 DC3 DC4 ERR SYNC LEM S0 S1 S2 S3 S4 S5 S6 S7


16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

0 1 2 3 4 5 6 7 8 9
48 49 50 51 52 53 54 55 56 57

DEL
127

[email protected] (STM) Imperative programming 6 / 10


The ASCII table

The ASCII table

Control Characters, Numeric Digits, Alphabetical Characters


(english),
NULL SOM EOA EOM EOT WRU RU BELL FE0 HT LF VTAB FF CR SO SI
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

DC0 DC1 DC2 DC3 DC4 ERR SYNC LEM S0 S1 S2 S3 S4 S5 S6 S7


16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

0 1 2 3 4 5 6 7 8 9
48 49 50 51 52 53 54 55 56 57

A B C D E F G H I J K L M N O
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

P Q R S T U V W X Y Z
80 81 82 83 84 85 86 87 88 89 90

a b c d e f g h i j k l m n o
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

p q r s t u v w x y z DEL
112 113 114 115 116 117 118 119 120 121 122 127

[email protected] (STM) Imperative programming 6 / 10


The ASCII table

The ASCII table

Control Characters, Numeric Digits, Alphabetical Characters


(english), Punctuation
NULL SOM EOA EOM EOT WRU RU BELL FE0 HT LF VTAB FF CR SO SI
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

DC0 DC1 DC2 DC3 DC4 ERR SYNC LEM S0 S1 S2 S3 S4 S5 S6 S7


16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

␣ ! " # $ % & ’ ( ) * + , - . /
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

0 1 2 3 4 5 6 7 8 9 : ; < = > ?
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

@ A B C D E F G H I J K L M N O
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79

P Q R S T U V W X Y Z [ \ ] ^ _
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

‘ a b c d e f g h i j k l m n o
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

p q r s t u v w x y z { | } ~ DEL
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

[email protected] (STM) Imperative programming 6 / 10


The ASCII table

The ASCII table

The ascii code is internally used by C to represent a character


So when you create a new character the value stored in memory
is really it’s code
Actually, this two blocks of code have the same exact result:

%c in the printf above → formats the output as a character


If we change it to %d (integer) we get the actual ascii code:
char c = 'A ';
printf ( " The ascii code of % c is % d \ n " , c , c ) ;

Terminal :
The ascii code of A is 65

(Try changing the value from ’A’ to another character and see what happens. . . )

[email protected] (STM) Imperative programming 7 / 10


The ASCII table

The ASCII table

The ascii code is internally used by C to represent a character


So when you create a new character the value stored in memory
is really it’s code
Actually, this two blocks of code have the same exact result:

%c in the printf above → formats the output as a character


If we change it to %d (integer) we get the actual ascii code:
char c = 'A ';
printf ( " The ascii code of % c is % d \ n " , c , c ) ;

Terminal :
The ascii code of A is 65

(Try changing the value from ’A’ to another character and see what happens. . . )

[email protected] (STM) Imperative programming 7 / 10


The ASCII table

The ASCII table

The ascii code is internally used by C to represent a character


So when you create a new character the value stored in memory
is really it’s code
Actually, this two blocks of code have the same exact result:

%c in the printf above → formats the output as a character


If we change it to %d (integer) we get the actual ascii code:
char c = 'A ';
printf ( " The ascii code of % c is % d \ n " , c , c ) ;

Terminal :
The ascii code of A is 65

(Try changing the value from ’A’ to another character and see what happens. . . )

[email protected] (STM) Imperative programming 7 / 10


The ASCII table

The ASCII table

The ascii code is internally used by C to represent a character


So when you create a new character the value stored in memory
is really it’s code
Actually, this two blocks of code have the same exact result:
char c = 'A '; char c = 65 ;
printf ( " % c \ n " , c ) ; printf ( " % c \ n " , c ) ;
%c in the printf above → formats the output as a character
If we change it to %d (integer) we get the actual ascii code:
char c = 'A ';
printf ( " The ascii code of % c is % d \ n " , c , c ) ;

Terminal :
The ascii code of A is 65

(Try changing the value from ’A’ to another character and see what happens. . . )

[email protected] (STM) Imperative programming 7 / 10


The ASCII table

The ASCII table

The ascii code is internally used by C to represent a character


So when you create a new character the value stored in memory
is really it’s code
Actually, this two blocks of code have the same exact result:
char c = 'A '; char c = 65 ;
printf ( " % c \ n " , c ) ; printf ( " % c \ n " , c ) ;
%c in the printf above → formats the output as a character
If we change it to %d (integer) we get the actual ascii code:
char c = 'A ';
printf ( " The ascii code of % c is % d \ n " , c , c ) ;

Terminal :
The ascii code of A is 65

(Try changing the value from ’A’ to another character and see what happens. . . )

[email protected] (STM) Imperative programming 7 / 10


The ASCII table

The ASCII table

The ascii code is internally used by C to represent a character


So when you create a new character the value stored in memory
is really it’s code
Actually, this two blocks of code have the same exact result:
char c = 'A '; char c = 65 ;
printf ( " % c \ n " , c ) ; printf ( " % c \ n " , c ) ;
%c in the printf above → formats the output as a character
If we change it to %d (integer) we get the actual ascii code:
char c = 'A ';
printf ( " The ascii code of % c is % d \ n " , c , c ) ;

Terminal :
The ascii code of A is 65

(Try changing the value from ’A’ to another character and see what happens. . . )

[email protected] (STM) Imperative programming 7 / 10


The ASCII table

The ASCII table

The ascii code is internally used by C to represent a character


So when you create a new character the value stored in memory
is really it’s code
Actually, this two blocks of code have the same exact result:
char c = 'A '; char c = 65 ;
printf ( " % c \ n " , c ) ; printf ( " % c \ n " , c ) ;
%c in the printf above → formats the output as a character
If we change it to %d (integer) we get the actual ascii code:
char c = 'A ';
printf ( " The ascii code of % c is % d \ n " , c , c ) ;

Terminal :
The ascii code of A is 65

(Try changing the value from ’A’ to another character and see what happens. . . )

[email protected] (STM) Imperative programming 7 / 10


The ASCII table

The ASCII table

The ascii code is internally used by C to represent a character


So when you create a new character the value stored in memory
is really it’s code
Actually, this two blocks of code have the same exact result:
char c = 'A '; char c = 65 ;
printf ( " % c \ n " , c ) ; printf ( " % c \ n " , c ) ;
%c in the printf above → formats the output as a character
If we change it to %d (integer) we get the actual ascii code:
char c = 'A ';
printf ( " The ascii code of % c is % d \ n " , c , c ) ;

Terminal :
The ascii code of A is 65

(Try changing the value from ’A’ to another character and see what happens. . . )

[email protected] (STM) Imperative programming 7 / 10


Strings (introduction)

Summary

1 The ASCII table

2 Strings (introduction)

[email protected] (STM) Imperative programming 8 / 10


Strings (introduction)

Strings (introduction)
String - Finite sequence of characters - letters, numbers, symbols
and punctuation marks
In C you define a string literal with a sequence of characters
between double-quotes (") - "A string literal!"
This is different from the single character (char) literal, between
single-quotes - 'X'
The above string literal is composed of the individual characters:
'A',' ','s','t','r','i','n','g',' '
'l','i','t','e','r','a','l','!','\0'
An ’\0’ (ascii code 0) marks the end of the string
Automatically placed when you define it between double-quotes. . .
We have been using string literals in the text format argument of the
printf function:

[email protected] (STM) Imperative programming 9 / 10


Strings (introduction)

Strings (introduction)
String - Finite sequence of characters - letters, numbers, symbols
and punctuation marks
In C you define a string literal with a sequence of characters
between double-quotes (") - "A string literal!"
This is different from the single character (char) literal, between
single-quotes - 'X'
The above string literal is composed of the individual characters:
'A',' ','s','t','r','i','n','g',' '
'l','i','t','e','r','a','l','!','\0'
An ’\0’ (ascii code 0) marks the end of the string
Automatically placed when you define it between double-quotes. . .
We have been using string literals in the text format argument of the
printf function:

[email protected] (STM) Imperative programming 9 / 10


Strings (introduction)

Strings (introduction)
String - Finite sequence of characters - letters, numbers, symbols
and punctuation marks
In C you define a string literal with a sequence of characters
between double-quotes (") - "A string literal!"
This is different from the single character (char) literal, between
single-quotes - 'X'
The above string literal is composed of the individual characters:
'A',' ','s','t','r','i','n','g',' '
'l','i','t','e','r','a','l','!','\0'
An ’\0’ (ascii code 0) marks the end of the string
Automatically placed when you define it between double-quotes. . .
We have been using string literals in the text format argument of the
printf function:

[email protected] (STM) Imperative programming 9 / 10


Strings (introduction)

Strings (introduction)
String - Finite sequence of characters - letters, numbers, symbols
and punctuation marks
In C you define a string literal with a sequence of characters
between double-quotes (") - "A string literal!"
This is different from the single character (char) literal, between
single-quotes - 'X'
The above string literal is composed of the individual characters:
'A',' ','s','t','r','i','n','g',' '
'l','i','t','e','r','a','l','!','\0'
An ’\0’ (ascii code 0) marks the end of the string
Automatically placed when you define it between double-quotes. . .
We have been using string literals in the text format argument of the
printf function:

[email protected] (STM) Imperative programming 9 / 10


Strings (introduction)

Strings (introduction)
String - Finite sequence of characters - letters, numbers, symbols
and punctuation marks
In C you define a string literal with a sequence of characters
between double-quotes (") - "A string literal!"
This is different from the single character (char) literal, between
single-quotes - 'X'
The above string literal is composed of the individual characters:
'A',' ','s','t','r','i','n','g',' '
'l','i','t','e','r','a','l','!','\0'
An ’\0’ (ascii code 0) marks the end of the string
Automatically placed when you define it between double-quotes. . .
We have been using string literals in the text format argument of the
printf function:

[email protected] (STM) Imperative programming 9 / 10


Strings (introduction)

Strings (introduction)
String - Finite sequence of characters - letters, numbers, symbols
and punctuation marks
In C you define a string literal with a sequence of characters
between double-quotes (") - "A string literal!"
This is different from the single character (char) literal, between
single-quotes - 'X'
The above string literal is composed of the individual characters:
'A',' ','s','t','r','i','n','g',' '
'l','i','t','e','r','a','l','!','\0'
An ’\0’ (ascii code 0) marks the end of the string
Automatically placed when you define it between double-quotes. . .
We have been using string literals in the text format argument of the
printf function:
int a = 1 ; string literal
printf ( " The value of a is % d \ n " , a ) ;

[email protected] (STM) Imperative programming 9 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;

char ackbar = "It's a trap";

char episode_iv = ’A new hope’;

char two_chars = ’AB’;

char two_chars = 10;

printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";

char episode_iv = ’A new hope’;

char two_chars = ’AB’;

char two_chars = 10;

printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";

char episode_iv = ’A new hope’;

char two_chars = ’AB’;

char two_chars = 10;

printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";
char ackbar declares a single char, not suitable for a string
char episode_iv = ’A new hope’;

char two_chars = ’AB’;

char two_chars = 10;

printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";
char ackbar declares a single char, not suitable for a string
char episode_iv = ’A new hope’;

char two_chars = ’AB’;

char two_chars = 10;

printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";
char ackbar declares a single char, not suitable for a string
char episode_iv = ’A new hope’;
single-quotes (’) are not suitable for a string initialization
char two_chars = ’AB’;

char two_chars = 10;

printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";
char ackbar declares a single char, not suitable for a string
char episode_iv = ’A new hope’;
single-quotes (’) are not suitable for a string initialization
char two_chars = ’AB’;

char two_chars = 10;

printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";
char ackbar declares a single char, not suitable for a string
char episode_iv = ’A new hope’;
single-quotes (’) are not suitable for a string initialization
char two_chars = ’AB’;
char literal between single-quotes (’) can only have 1 char
char two_chars = 10;

printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";
char ackbar declares a single char, not suitable for a string
char episode_iv = ’A new hope’;
single-quotes (’) are not suitable for a string initialization
char two_chars = ’AB’;
char literal between single-quotes (’) can only have 1 char
char two_chars = 10;

printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";
char ackbar declares a single char, not suitable for a string
char episode_iv = ’A new hope’;
single-quotes (’) are not suitable for a string initialization
char two_chars = ’AB’;
char literal between single-quotes (’) can only have 1 char
char two_chars = 10;
the two_chars variable will have the ’\n’ special character
printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";
char ackbar declares a single char, not suitable for a string
char episode_iv = ’A new hope’;
single-quotes (’) are not suitable for a string initialization
char two_chars = ’AB’;
char literal between single-quotes (’) can only have 1 char
char two_chars = 10;
the two_chars variable will have the ’\n’ special character
printf("%c\n", "Bla!");

[email protected] (STM) Imperative programming 10 / 10


Strings (introduction)

Strings (introduction) - Quiz (characters and strings)

Try to figure out if the code snippets below are valid in C:


char question_mark = 63;
63 represents the ascii char ’?’
char ackbar = "It's a trap";
char ackbar declares a single char, not suitable for a string
char episode_iv = ’A new hope’;
single-quotes (’) are not suitable for a string initialization
char two_chars = ’AB’;
char literal between single-quotes (’) can only have 1 char
char two_chars = 10;
the two_chars variable will have the ’\n’ special character
printf("%c\n", "Bla!");
%c → would print random char in terminal, correct → %s

[email protected] (STM) Imperative programming 10 / 10

You might also like