ASCII
ASCII codes
As a high level programmer we see our laptop keyboard
as a bunch of keys with character printed on them
& some special keys like ,
that key with windows logo
alt key, ctrl key, num-lock etc
using ASCII codes,
we encode all of this character
i.e., we assign a bit pattern to each of these character
e.g. for
alphabetic character 'A' ≣ 65(in decimal) ≣ 1000001(in binary)
space character ' ' ≣ 32(in decimal) ≣ 0100000(in binary)
Now let's run a C++ pgm that prints 'A'
there are two alternatives,
we directly initialize a character with 'A'
or we can initialize character with 65
#include<bits/stdc++.h>
using namespace std;
int main(){
char c1 = 'A';
char c2 = 65;
cout << c1 ;
cout << c2;
return 0;
}
g++ --version // to chk g++ version installed in your windows10 PC
g++ -g code.cpp -o code.exe // to compile code
// after compiling code a binary file code.exe is created
code.exe // running executable file
C++ pgm to produce alert sound
there are non printable characters (or whitespace character)
like '\n' : to print newline character
like '\t' : to print tab
similarly we have '\a' : to produce alert sound
#include<bits/stdc++.h>
using namespace std;
int main(){
cout << '\a';
return 0;
}
you can how it sounds when we run the program
It's a alert sound
Similarly we have other whitespace or special character.
For more interesting codes like Unicode currently
you can refer here
Comments
Post a Comment