When should I use the new keyword in C++?

Method 1 (using new) Allocates memory for the object on the free store (This is frequently the same thing as the heap) Requires you to explicitly delete your object later. (If you don’t delete it, you could create a memory leak) Memory stays allocated until you delete it. (i.e. you could return an object that you created using new) The example in the question will leak memory unless … Read more

Invalid pointer error on invoking free() after malloc in C

I am doing very basic dynamic allocation practice in C and I came across this issue: when I am trying to call free() with the pointer returned by malloc(), I am getting Invalid pointer error during run time. When I remove free() from code, it works fine. The pointer that I am using is not modified anyhow after returned by malloc (except … Read more

How do you pass a function as a parameter in C?

Declaration A prototype for a function which takes a function parameter looks like the following: This states that the parameter f will be a pointer to a function which has a void return type and which takes a single int parameter. The following function (print) is an example of a function which could be passed to func as a parameter because it is … Read more

#31 expression must have integral type

I’m having some problems with my C code and get the error in the title. First off, Uint16 is defined as: I use two variables in the function where I get the error, they are defined as: I call the function like this: and the function definition is like this: and lastly, the declaration in … Read more

What’s the difference between char and char* in C++?

The variables with the * are pointers. A ‘normal’ variable, for example a char or an int, contains the value of that datatype itself – the variable can hold a character, or an integer. A pointer is a special kind of variable; it doesn’t hold the value itself, it contains the address of a value in memory. … Read more

What does ** do in C language?

In C arguments are passed by values. For example if you have an integer varaible in main and the following function then if you call the function in main like this then the parameter gets the value of variable x in main. However the parameter itself occupies a different extent in memory than the argument. So any … Read more

Difference between char* and const char*?

char* is a mutable pointer to a mutable character/string. const char* is a mutable pointer to an immutable character/string. You cannot change the contents of the location(s) this pointer points to. Also, compilers are required to give error messages when you try to do so. For the same reason, conversion from const char * to char* is deprecated. char* const is an immutable pointer (it cannot point to any other location) but the contents … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)