1#include <iostream>
2using namespace std;
3int main() {
4 char grade = 'B';
5 cout << "I scored a: "<<grade;
6 return 0;
7}
8
1#include <iostream>
2using namespace std;
3
4int main()
5{
6 char* name = "Raj"; //can store a sequence of characters.
7 const char* school = "oxford";
8 //school[0] = 'O'; //gives runtime error. We can't modify it.
9 cout << name<<" "<<school;
10
11 return 0;
12}
1isdigit() - Check if character is decimal digit
2isalpha() - Check if character is alphabetic
3isblank() - Check if character is blank
4islower() - Check if character is lowercase letter
5isupper() - Check if character is uppercase letter
6isalnum() - Check if character is alphanumeric
1// strings and NTCS:
2#include <iostream>
3#include <string>
4using namespace std;
5
6int main ()
7{
8 char question1[] = "What is your name? ";
9 string question2 = "Where do you live? ";
10 char answer1 [80];
11 string answer2;
12 cout << question1;
13 cin >> answer1;
14 cout << question2;
15 cin >> answer2;
16 cout << "Hello, " << answer1;
17 cout << " from " << answer2 << "!\n";
18 return 0;
19}
1
2// syntax:
3// char <variable-name>[] = { '<1st-char>', '<2nd-char>', ... , '<Nth-char>', '\0'};
4
5// example (to store 'Hello' in the YourVar variable):
6char YourVar[] = {'H','e','l','l','o','\0'}; // NOTE: the \0 marks the end of the char array
7