[Solved] C does not support passing a variable by reference. How to do it?

You’re right, C does not support passing by reference (as it is defined by C++). However, C supports passing pointers. Fundamentally, pointers are references. Pointers are variables which store the memory address at which a variable can be located. Thus, standard pointers are comparable C++ references. So in your case, void Foo(char *k, struct_t* &Root) … Read more

[Solved] Is return *array; valid? [closed]

Yes and no. Yes, because it is the way you should return it. No, because you should (and have to) use new[] operator (or malloc function). So basically you should write: int* function(int n){ int i = 0; int *array = new int[n]; // or c-style malloc(n*sizeof(int)) for(i = 0; i<=n ; i++){ array[i] = … Read more

[Solved] Cannot get pointers result

I can only assume, that an expected behavior is to get variable v incremented 10 times using pointer. If that’s correct, you have two mistakes: Type of pointer should be the same with the data you’re pointing. If you’re pointing at int variable, you should use int * pointer. In the for loop condition: at … Read more

[Solved] ‘ ‘ was not declared in this scope [closed]

If you want to implement the dynamic array management within a class, you need to qualify your method implementations with the class name. dynamicArray.cpp int * dynamicArray::array_constructor(int * &intPtr, int &size ){ if(intPtr != NULL){ // … other member functions the same thing. However, you don’t really use your class in a class-like way at … Read more

[Solved] what is the reason of this error?

The problem is that the class definitions are not visible to the compiler when you try to access members of an instance. Although you have provided forward declarations for the classes this is not enough. In the .cpp and .h files that access members of these classes or require their sizes you need to include … Read more

[Solved] Problems with char * and delete [duplicate]

You can delete only what was allocated using the corresponding operator new. String literals have static storage duration. They are not dynamically allocated. According to the C++ Standard 8 Ordinary string literals and UTF-8 string literals are also referred to as narrow string literals. A narrow string literal has type “array of n const char”, … Read more

[Solved] I have a segmentation fault and am unsure about what is wrong with my code

The problem is obvious now you’ve said on which line the code crashes. Consider these lines… char *word = NULL; int i = 0; //index FILE *dictionaryTextFile; dictionaryTextFile = fopen(dictionary, “r”); //scan for word while(fscanf(dictionaryTextFile, “%s”, word) != EOF) You’ve got 2 problems there. Firstly, you don’t check that the call to fopen worked. You … Read more

[Solved] Purpose of void*

Try to compile you code with a serious ANSI C compiler, from C89 to C11, and you will get the same error: Test.c(9): error #2168: Operands of ‘=’ have incompatible types ‘double *’ and ‘int *’. Test.c(11): error #2168: Operands of ‘=’ have incompatible types ‘double *’ and ‘char *’. Test.c(13): error #2168: Operands of … Read more

[Solved] Advice on how to resolve this error.

A typical linked list structure is made of three parts The Data class Bunny { string name; // don’t use pointers unless you really, really need them int age; bool gender; string color; bool radioactive_bunny; public: string getGender(); // don’t need to know which Bunny anymore because // these functions are bound to a particular … Read more

[Solved] How to access the object of the class where “=” operator is disabled?

Hmmm Some task… Do one thing create a pointer of that class in your cpp file and assign memory to it using heap allocation. class *myfield = (class*)malloc(no_of_instances*sizeof(class)) Now use that object which is there in your header file assign myfield’s address to that object(hope that is pointer) Now it should work fine.. try and … Read more