Having some serious problems wrapping my head around how to pass a 2D array to a function in C - pointers are not my strong point!
I need to have a function which takes a 2D array and generates random bits, so the result is an array of random binary strings.
Currently I have
#define pop_size 50
#define chrom_length 50
main() {
int...
Is there a simple, efficient weak/guarded pointer? I need multiple pointers to the same object that are all automatically set to NULL when the object is deleted. There is one "master" pointer that is always used to delete the object, but there can be several other pointers that reference the same object.
Here are some solutions that don...
My brain has never really quite grasped linked lists and the finer points of pointers but I'm trying to help out a friend with some C++ assignments. (And before I go any further, yes, there is std::list but I'm looking for an academic answer, and maybe something that will make linked lists more understandable to he and myself).
What we ...
When do we need to use "assert" for pointers in C++, and when they are used, how are they most commonly implemented?
...
Hi there!
I am attempting to tackle college worksheet on C programming (no marking for it, just to improve our learning). What we're meant to do is get a few details about shipping docks. I decided to use structures for this.
My code is below, what I need help with is to print out the information (to see if its working) of whats at the...
There seem to be two arguments why one should set a pointer to NULL after freeing them.
Avoid crashing when double-freeing pointers.
Short: Calling free() a second time, by accident, doesn't crash when it's set to NULL.
Almost always this masks a logical bug because there is no reason to call free() a second time. It's safer to let t...
I am expecting that both following vectors have the same representation in RAM:
char a_var[] = "XXX\x00";
char *p_var = "XXX";
But strange, a call to a library function of type f(char argument[]) crushs the running application if I call it using f(p_var). But using f(a_var) is Ok!
Why?
...
Is there any way to maintain the same functionality in the code below, but without having to create the delegate? I'm interfacing with a 3rd-party API that contains a number of various DeleteSomethingX(ref IntPtr ptr) methods and I'm trying to centralize the code for the IntPtr.Zero check.
private void delegate CleanupDelegate(ref IntP...
NOTE: THIS IS FOR HOMEWORK SO PLEASE DO NOT INCLUDE BLOCKS OF CODE IN YOUR ANSWERS
I have an assignment that requires us to implement a doubly linked list class. For some reason they defined the node struct as follows:
struct node {
node *next;
node *prev;
T *o;
};
It seems to me that it would be a lot easier to write ...
Ok so let's say we have a linked list of characters with a head pointer. How can I create a loop to enter a string of characters into the linked list? My problem is when I think of head and head->next and head->next->next . . . it only seems natural to use a recursive function to set the characters at each node.
...
In my C program this function is going to handle all the work of opening a specific file and then return the file pointer, so main or other functions can read the content by using fp, but so far i haven't been able to get this to work.
I'm just learning the language, so it is possible that i am doing something very wrong.
int open_text...
Hi,
I'm currently learning libgmp and to that end I'm writing a small program which find prime factors. My program calls a function which fills an array with a varying amount of mpz_t integers, prime factors of a given number, which I need to return. I'm planning on setting the last element to NULL, so I know how many mpz_t integers the...
I'm reading The C Book to try and get a better foundation in C. While I think I'm generally getting the concept of pointers, one thing sticks out to me is that it seems like it's generalizing whatever it's pointing to into a global variable (e.g. the ability to use pointers to return values from void functions), which naturally carries...
What does this line mean? I havn't done C in a few years. Does it perform the operation in parens then make the int result a pointer??
b[0] = *(start + pos++);
...
I have some C code that I'd like to port to java. I haven't done much C coding, but I was able to follow along up until this one function. If anyone could help me understand what is going on, it would be greatly appreciated.
int reverse_integer(int input) {
int output = 0, i;
for ( i=0, i<sizeof(int); i++ ) {
output =...
What is the difference between pointer to a reference, reference to a pointer and pointer to a pointer in C++?
Where should one be preferred over the other?
...
Suppose there exists a function which returns a message
say of the following format:
struct message
{
void* data;
}msgG;
Which would be the best way to extract the data (i.e. Get the message accessible to fun1 in the code):
1- using a global variable
2- Using double pointers(pointer to a pointer)
//Note: msgG is the global variable
...
I would like to know the technical reason(in terms of memory) why this piece of code will not work:
#include <stdio.h>
#include <stdlib.h>
int* fun(int*);
int main()
{
int a=5;
int* ptr;
// ptr=(int*)malloc(sizeof(int));
fun(ptr);
a=*ptr;
printf("\n the val of a is:%d",a);
return 0;
}
void fun(int* ptr)
{
ptr = (int...
I thought I'm pretty experienced in java, but it seems that's not really the case, I just noticed something yesterday, something I used before but never really realised what it did. I googled but didn't find the answer to my question.
If I declare an int array, and use Array's static sort function to sort my array, I just need to type
...
I am confused in AddressOf in c# and pointer in c++ ?
Am i right that Addressof is manage execution and pointer is unmanage execution or something else?
...