difference with colon and semicolon.

What the difference between this code :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include<iostream>
using namespace std;

void main(){
	char a('1');
	char b('2');
	char c('3');
	char d('4');
	char e('5');
	char f('6');
	char g('7');
	char h('8');
	char i('9');
	char p1('x');
	char p2('o');
	
	system("pause");
}

with this code :
#include<iostream>
using namespace std;

void main(){
char a("1");
char b("2");
char c("3");
char d("4");
char e("5");
char f("6");
char g("7");
char h("8");
char i("9");
char p1("x");
char p2("o");

system("pause");
}
the second code should not compile, here's why :

char can only hold a single character, a character literal is determined through single quotes wrapping it -> ' '

when you are using double quotes " " it is interpreted as a string literal, (const char*), or a series of char's

so, in this initialization :
char a( "1" );

you are actually assigning a const char* to a char ( because of " ", it is interpreted as const char* more than one char ) w/c is not possible since char can only hold a single value

BTW, void main() should be int main()

Edit i think your title should be difference between quotes and double quotes instead
Last edited on
thx for helping bro
Topic archived. No new replies allowed.