Please register to have access to more features!

It is highly recommended that you have Javascript enabled; many features will not work unless you do. The recommended browsers are Firefox and Chrome; the board is also NOT mobile-friendly.

Please invite your friends!

If you were referred by someone (ex. me, Jessica) please put their username in the referral box on the registration page. Ask them if you don't know their username.

If you are visiting for TESTING PURPOSES ONLY, this is the test account information:

Password: test123

Select a forum to post in:

Search found 1 match

Return to: Difference between Linux C and C++

Difference between Linux C and C++

You cannot implicitly assign from a void* to any other type.
int *x = malloc(sizeof(int) * 10);
This will compile in C but not C++

HOWEVER this will work in C++
int an_int;
void *void_pointer = &an_int;
double *double_ptr = void_pointer;
*double_ptr = 5;

Because Code NO.1 Is not a "safe" type.
This means that you can have a void* that points to anything at all, and if you then assign the address stored in that void* to another pointer of a different type, there isn't any warning at all about it.

In C, there's only one major memory allocation function: malloc. You use it to allocate both single elements and arrays:
int *x = malloc( sizeof(int) );
int *x_array = malloc( sizeof(int) * 10 );

and you always release the memory in the same way:
free( x );
free( x_array );

In C++, however, memory allocation for arrays is somewhat different than for single objects; you use the new[] operator, and you must match calls to new[] with calls to delete[] (rather than to delete).
int *x = new int;
int *x_array = new int[10];
delete x;
delete[] x_array;

The short explanation is that when you have arrays of objects, delete[] will properly call the destructor for each element of the array, whereas delete will not.

Although most good C code will follow this convention, in C++ it is strictly enforced that all functions must be declared before they are used. This code is valid C, but it is not valid C++:
#include <stdio.h>
int main()
return 0;

int foo()
printf( "Hello world" );

You must declare functions before use

C++ has a much larger library than C, and some things may be automatically linked in by C++ when they are not with C. For instance, if you're used to using g++ for math-heavy computations, then it may come as a shock that when you are using gcc to compile C, you need to explicitly include the math library for things like sin or even sqrt:
% g++ foo.cc


% gcc foo.c -lm

C does not provide a native boolean type. You can simulate it using an enum, though:
typedef enum {FALSE, TRUE} bool;

In C++, you are free to leave off the statement 'return 0;' at the end of main; it will be provided automatically:
int main()
printf( "Hello, World" );

but in C, you must manually add it:
int main()
printf( "Hello, World" );
return 0;

P.S. Not related to topic
This forum seems to be a bit unstable. I noticed much security loopholes both in login and registration mode. Also, it seems to be using the free or premium( i don't know) shared hosting package from x10hosting. This is seriously not recommended. A forum this heavily modded will crash soon in a shared hosting package. X10 hosting does not allow the use of over 0.20 server load for over 60 seconds. Once the forum grows and bots start visiting, these MODs will cause a serious CPU hog. This would force X10hosting to terminate the website as stated in their acceptable use policy.
by technogeek12
February 14th, 2014, 5:59 am
Forum: ICT Topics
Topic: Difference between Linux C and C++
Replies: 1
Views: 3,640

Return to: Difference between Linux C and C++

Reputation System ©'