getting error on compiling the following code

Q1:
(a)I am using the following code and try to compile using devC++ but can't succeeded. what should i do.

Code no:1
#include <conio.h>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])

{

printf ("This is a computer age.");

getch()
return EXIT_SUCCESS;
}

The return EXIT_SUCCESS; highlighted with brown colour

Code No:2
#include <iostream.h>
#include <conio.h>

void main()
{
clrsrc();
char ch1, ch2,sum;
ch1='A';
ch2='B';
cout<<''Characters are:''<<ch1<<ch2;
getch();
}
Also getting error on these code on compiling

(b) The above two codes are which one belongs to c and which one to C++?

Question no.2
(a)I want to know that this site is teaching c or C++ language?
(b)i am the beginner and can't understand the differentiation both of these two. what is difference among them?
Last edited on
You are missing a semicolon on the line above.
Code no 1:
1
2
3
4
5
6
7
int main(int argc, char *argv[])
{
printf ("This is a computer age.");
getch() //you forget the ; here, hence the error message

return EXIT_SUCCESS;
}


code no 2: is written in C
1
2
3
4
5
6
7
8
9
10
11
12
13
Code No:2
#include <iostream.h>
#include <conio.h>

void main()
{
clrsrc();
char ch1, ch2,sum;
ch1='A';
ch2='B';
cout<<''Characters are:''<<ch1<<ch2;
getch();
}



This site? C++ just as the name suggested
Last edited on
code no 2: is written in C


The cout makes it C++ as far as that goes - people do write C type code with cout's etc. The first one is C.

use std::cout and it will work, although there could be problems with the clrsrc();
code 1 is C?
as far as I know, I can use printf in C++ as well.
and the way main() is written as
1
2
3
4
int main()
{
     return EXIT_SUCCESS; 
}

tells me the same thing too

unless I overlooked or skipped something?

as for code 2: You are probably right. I was looking at void main() and jumped to conclusion it was C
You can use any C stuff in a C++ program, however if it is exclusively C stuff then it's a C program.

If it has cout in it, then it's definitely C++, because you can't do that in C.

and the way main() is written as


1
2
3
4
int main()
{
     return EXIT_SUCCESS; 
}



tells me the same thing too


well that looks exactly like C to me, why would you think it was C++ ?

as for code 2: You are probably right. I was looking at void main() and jumped to conclusion it was C


I am not sure but void main() would have probably been at least a warning in C, if not an error. Different in C++, apparently since C99, one has been allowed to do this sort of thing - no return statement at end of main either.

AFAIK C programs are like this:

1
2
3
4
5
6
int main(int argc, char *argv[])
{
printf ("This is a computer age.");

return 0;
}


edit: main returns an int

The argc and argv stuff is optional and you can do that in C++
too.

The EXIT_SUCCESS and similar stuff are just another way of returning a value to the OS.
Last edited on
as in C++,
you have main as int and return value

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

using namespace std;

int main()
{
 	
 	cin.get();
 	return 0;
}


is it not how it is?
How does it look like C to you?

by google the most basic Hello World in C. I got:
1
2
3
4
5
6
7
#include<stdio.h>

main()
{
    printf("Hello World");

}


or
1
2
3
4
5
6
#include < stdio.h>

void main()
{
    printf("\nHello World\n");
}



The argc and argv stuff is optional and you can do that in C++
too.

The EXIT_SUCCESS and similar stuff are just another way of returning a value to the OS.


this EXIT stuff wasnt what I was talking about. I know it is optional though.
Last edited on
Ok the C std has changed also (Peter87 has pulled me up about this before) by the looks of it, so you can do this :

1
2
3
4
5
6
#include < stdio.h>

void main()
{
    printf("\nHello World\n");
}


And the other one as you have said.

I guess I am stuck in the mud a bit - I started C programming in 1987 so that's why I have this on the brain:

1
2
3
4
5
6
int main(int argc, char *argv[])
{
printf ("This is a computer age.");

return 0;
}


And still do it that way.

Apart from all that, what grabbed my attention was you were calling a program with cout in it a C program which is definitely wrong, and the other program was clearly C.

Any way hope we are all square now.
thank you ^^
Topic archived. No new replies allowed.