Address of address of a variable

I was experimenting the behaviors of pointer in C. I wrote the following program: #include <stdio.h> main(){ int a = 1; printf("%p\n", &&a); } I knew that this program would give error. Because an address of address would be ...
more »

2017-08-09 12:08 (5) Answers

What is the type of a pointer to a 2D array?

I know that the following is not correct: int arr[2][3] = {}; //some array initialization here int** ptr; ptr = arr; But I am quite surprised that the following lines actually work int arr[2][3] = {}; //some array initialization here auto ptr = a...
more »

2017-07-31 09:07 (4) Answers

C++ function with pointer argument

I am writing a C++ program that outputs data to a file, generates a python script and calls pyplot to make the plotting. However, when I pass the arguments in terms of the pointers, it can be compiled properly, but cannot run. It returns error. Wh...
more »

2017-07-28 01:07 (3) Answers

C++ pointer to an array of ints

int main(){ int a[4] = { 1,2,3,4 }; int(*b)[4] = &a; //with a doesn't work cout << a << &a << endl; //the same address is displayed } So, int(*b)[4] is a pointer to an array of ints. I tried to initialize it w...
more »

2017-07-20 04:07 (2) Answers

Suspicious memory management implications

So in an attempt to solidify my understanding of pointers and memory management in general in C, I decided to do a basic implementation of a linked list. I'm very suspicious of certain things in my code though, and was wondering if I could get some ...
more »

2017-07-13 13:07 (2) Answers

Initializing C struct using pointer to pointer

I'm working on creating a hash table implementation for an assignment. I've defined my hashtable as struct as follows: typedef struct hashtable { int size; int entries; int table*; // pointer to table. Each entry will point to linked list ...
more »

2017-07-13 00:07 (5) Answers

C: Passing any function to a function

I would like to know how I would go about passing any function to a function, as in a generic function pointer that can take any function whatsoever, The goal of this is to make a destructor system, so basically storing the function and calling it wi...
more »

2017-07-09 21:07 (2) Answers

Segmentation fault after realloc in function

I have created this code to test one error, that I get in my main code, and it shares the same problem. I'm always getting either segmentation fault or corrupted data (zeros or strange numbers). Here is the code: int *p=NULL; int func (int **point)...
more »

2017-07-09 08:07 (1) Answers

Pointer Problems and Dynamically allocating Memory

I'm working on an exercise that will eventually turn into a pthread experiment for educational purposes. Here I'm taking a list (the alphabet) and trying to get five lists of numbers that I can feed to a pthread to analyze something. For example, num...
more »

2017-07-02 10:07 (2) Answers

How to shift chars w/pointers

I'm trying to write a function in C which shifts each letter of a char *, so 'a' becomes 'z' and 'b' becomes 'y'. In the if statements below, it's my understanding that (*p - 'a') is the letter p points to, but I'm not sure how to shift the char to a...
more »

2017-07-01 15:07 (4) Answers

Output process - save data in file

Briefly, I'm testing this code in python: My idea is to save solut = one + two in a file after inputting the values by keyboard, but now I have a problem. NO message error and nothing is written in file. python 2.7 I have changed and saved the cod...
more »

2017-06-20 05:06 (2) Answers

C "for" loop iterating only once

For context, I'm trying to write code that solve this problem in C. The problem is relatively simple. The first input is an integer that represent the number of scores in a stream of scores. The following inputs are all integers that represent scor...
more »

2017-06-17 21:06 (1) Answers

Size of pointers and dynamic arrays

I'm relatively new to C, and I've been messing around with pointers to an int array to help solidify my understanding. Here is some code I typed up that confused me: #include <stdio.h> int main(int argc, char **argv) { int sizeOfInt = si...
more »

2017-06-17 18:06 (3) Answers

Why is this pointer variable assignment allowed?

While debugging a program of mine, I stumbled upon a weird behaviour of the gcc compiler. I don't know what's the correct title to describe this, but take a look at the code below. Basically, I had a function which received a void* arg as an argumen...
more »

2017-06-17 12:06 (1) Answers

Initialize C struct through a function

So I do have to write a vector-like data structure in C. Generally I made a structure like this: struct Vector { int length; int *elements; }; And functions like these: void initialize_vector(struct Vector* vector); void create_vector(str...
more »

2017-06-15 20:06 (2) Answers

Compare between pointers and integer

I have a question, I tried to copy one line from a pointer to file but there is one error that says that I cannot compare a interger with a pointer, can anyone help me? The error is in line ch = getc(file1); and while(ch != EOF) #include <stdio.h...
more »

2017-06-14 22:06 (1) Answers

Why can't I print the value at this pointer?

Following yesterday's question, I experimented some more with pointers. Specifically pointers of type int (*) [n] Here's some code I wrote : #include <stdio.h> int main(void) { int a[5] = {1, 2, 3, 4, 5}; int (*p) [5] = &a; ...
more »

2017-06-14 09:06 (3) Answers