21 questions
2
votes
2
answers
80
views
Pulling values out of one multidimensional array and putting them into several 1D arrays (C)
I am trying to sort the values in the Data array into Column arrays X1,X2, and Y_actual. The code I have written out makes sense to me, and returns the correct array1,array2, and array3 values if I ...
0
votes
1
answer
127
views
Why is the value of the pointer pointing at the 0th index of an array different from the actual 0th index of the array in C?
Python programmer here. I know just the basics about C but I was given the task of taking n entries in an array then creating a function that takes an array pointer as its argument, and then accessing ...
-1
votes
1
answer
100
views
What is the actual practical difference between int x[] and int *x[] in C?
Although I've learned and worked with many advanced languages, but today when I was refreshing my C skills this old question again striked me. When we talk about pointers in C, simple pointers are ...
0
votes
0
answers
39
views
Address of the array name pointer and the first element of the array [duplicate]
Is the address of the first element of the array and the address of the array name pointer is same in C programming?
And what if we create a pointer(p) to the first element(a[0]) of the array(a[5]) ...
2
votes
0
answers
121
views
Why does a php array in two foreach loops lead to an infinite loop?
I have this PHP code:
$array = [1, 2, 3];
$counter = 0;
foreach($array as &$elem){
test();
$counter++;
if($counter >= 10){
return;
}
}
function test(){
global $...
0
votes
1
answer
30
views
value of array of pointers to struct changes when exiting loop
phonebook is an array of pointers.
inside the handleMenu im allocating memory and pointing to structure where a first name is assigned to a struct that is pointed from phonebook[11].
as you can see ...
0
votes
0
answers
50
views
Accessing specific objects using pointer to multiple arrays of pointers
EDIT: Pasting portion of code that is giving me this issue. Although in my effort to cleanup some of the comments before pasting it here I ended up with a different error. Still happens in the same ...
0
votes
1
answer
223
views
Meaning of 1[pointer] in C++? [duplicate]
Reading cppreference I found this example:
int a[4] = {1, 2, 3, 4};
int* p = &a[2];
std::cout << p[1] << p[-1] << 1[p] << (-1)[p] << '\n'; // 4242
I am confused ...
0
votes
2
answers
213
views
Pointer-to-array, malloc, and out-of-bounds access
Given a pointer-to-array in C, can we malloc to it enough memory for extra elements (beyond the specified array size) and then safely access those elements using either the [] operator or pointer ...
1
vote
2
answers
3k
views
C26485 and pointer decay with TCHAR in exception handler
I don't understand this C26485 warning I receive.
My code is an exception handler:
catch (CDBException* e)
{
TCHAR szError[_MAX_PATH];
e->GetErrorMessage(szError, _MAX_PATH);
...
1
vote
0
answers
45
views
What is the difference between these two methods of dynamic allocation of arrays?
I was going through array using pointers and I found two different dynamic allocation methods of an array
int *ptr_arr=new int[10];
This one was defined in the lectures but when I explored a bit I ...
2
votes
2
answers
208
views
How to read a complicated type?
I know that using type alias and typedef make the code so readable, less error-prone and easy modify. However in this example I want to know this complicated type:
#include <iostream>
#include &...
1
vote
1
answer
218
views
What is the implicit decay of char* arrays?
As a newbie, I'm solving a problem from K&R's pointers chapter and was confused with some aspects of character pointers, and passing an array of type char* as a function parameter.
Char array ...
2
votes
2
answers
151
views
C Pointer array is not working with memcpy
I would like to concatenate two string with memcpy. But next memcpy is not working. My expected output is "my name is khan".
#include <stdio.h>
#include <stdlib.h>
#include <...
0
votes
1
answer
69
views
confilicting types in C
i have this main and 2 more functions each on different file
/*decleration of the functions on one file*/
typedef double *mat[4][4];
void catcher(void *,mat *);
void findMat(mat *,char *,int *);
int ...
0
votes
1
answer
67
views
Is there a way to get the size of a three-dimensional vector using pointer notation?
I need to do something like this:
sizeof(int[width][height][8])
but unfortunately in c89 (the standard i have to use) this notation is forbidden, is there any way to do the same thing but using ...
1
vote
1
answer
60
views
Seg Fault calling mergesort on pointer array
I am trying to work with threads in C. I need one of my threads to work on one half of a whole array, and mergesort its half. To do this I created a global array pointer for the whole array and both ...
0
votes
2
answers
193
views
how to shrink an array if two consecutive numbers in an array are equal then remove one and increment other
How to shrink an array if two consecutive numbers in an array are equal then remove one and increment other
Example 1:
int a[6]={2,2,3,4,4,4};
// Output: 6
Example 2:
int b[7]={1,2,2,2,4,2,4};
// ...
0
votes
1
answer
68
views
Value of array pointer is getting changed after fopen
I am doing convolution operation for image. I have a problem in data stored in array pointer dynamically. The data in one of the array pointer variable is getting changed automatically after fopen ...
0
votes
2
answers
63
views
Is it possible to find the address of the end of an array with a reference to the n+1th element?
I need to know when the pointer went through the whole array -> is on the first position behind it.
Examplecode in c:
unsigned int ar[10];
char *pointer = (char*) ar;
while(pointer != (char*) &...
1
vote
3
answers
100
views
Understanding and manipulating pointers to integer arrays
I am having troubles with the following code:
int a[] = {1, 2, 3, 4};
fprintf(stdout,
"a : %lu\n"
"*a : %d\n"
"&a : %ld\n"
...