Skip to main content
Filter by
Sorted by
Tagged with
-2 votes
3 answers
192 views

It is easy to achieve this with typedef: typedef int (*ptr_arr)[]; // pointer to array But how to alias the same type as ptr_arr by using C++ using keyword? Also would be nice to see (good formatted)...
int main's user avatar
0 votes
1 answer
94 views

I asked a similar question before, when I didnt know what was the problem of my code. Just as I was recommended I will give it in a better format. This is an example of what happens to my code. #...
Acaymo Sánchez Ramirez's user avatar
0 votes
1 answer
177 views

I have a structure with several members of unsigned short type. The values stored in these types should be in a certain range, so I use a setter method for them that checks the range of the value ...
hdmi87's user avatar
  • 1
3 votes
7 answers
627 views

#include <stdio.h> int main() { int (*ptr) [5]; printf ("%lu\n" , sizeof (ptr)); printf ("%lu\n" , sizeof (*ptr)); } I am using 64 bit system. When I run this code in gcc ...
Baranitharan 's user avatar
0 votes
2 answers
40 views

Assume one dimensional array a={1,2,3,4} with base address as 100.Find the value of p. P=&a[0]; I know it will give tha base address of 0th element of 1D array. But in which order c compiler will ...
Roshan Rai's user avatar
1 vote
3 answers
210 views

I'm having strange warnings in Linux. In Visual Studio on Windows, the code compiles and works well but I need to compile it with GCC c90 I get these warnings: I've initialized the matrix like this: ...
Ruslan Ver's user avatar
0 votes
0 answers
2k views

I have an aggregation like this : this.collection.aggregate([ { "$match": { _id: id } }, { "$addFields": { "self&...
Sara's user avatar
  • 5
1 vote
1 answer
149 views

I’m confused about effective type in the case of pointers to arrays in C. Does accessing an individual member via a pointer to an array impart an effective type only on the memory for that member or ...
Jackson Allan's user avatar
24 votes
2 answers
2k views

In C, is it "legal" to under-allocate memory to a pointer-to-array if we then only access elements that fall within the allocated memory? Or does this invoke undefined behavior? int (*foo)[ ...
Jackson Allan's user avatar
0 votes
2 answers
216 views

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 ...
Jackson Allan's user avatar
1 vote
2 answers
110 views

On basis of the convention int (*o)[5]=&s; is the right way for a pointer o to point an array having 5 elements. We can also write this s in this statement int (*p)[10]=s; but why preferring &...
Ankit Bhardwaj's user avatar
0 votes
1 answer
183 views

I was learning about pointers and pointers to arrays, when I encountered this strange thing. Can anyone explain why this works? char str[] = "This is a String"; int *p = str; while(*p) std::...
Vjkaal's user avatar
  • 3
0 votes
2 answers
647 views

Suppose I get input from somewhere and store it in a variable. Pretend the variable is Cols. I want to make an array in the form int (*p)[Cols] Now, I know you can't do this. So how would I ...
V_S's user avatar
  • 27
-1 votes
3 answers
820 views

I am trying to understand how a pointer to an array works. A code snippet; #include<stdio.h> int main() { int arr[3] = { 0 , 8 ,10 }; int (*ptr)[3] = &arr; int i = 0; for (i = ...
Franc's user avatar
  • 470
0 votes
1 answer
90 views

would love for some help with understanding the difference between these two lines: int(*p)[20] = (int(*)[20]) malloc(sizeof(int) * 20); int* y = (int*)malloc(sizeof(int) * 20); if I do: int * tmp = ...
Roe's user avatar
  • 71
1 vote
2 answers
91 views

Given the code: int vector[5] = {1, 2, 3, 4, 5}; int *pv = vector, value = 3; for(int i = 0; i < 5; i++) { *pv++ *= value; } for(int i = 0; i < 5; i++) { printf("%d, ", *(pv+...
Axel Brugger's user avatar
8 votes
5 answers
6k views

int (*ptr)[10]; I was expecting ptr to be an array of pointers of 10 integers. I'm not understanding how it is a pointer to an array of 10 integers.
rahulvuppala v's user avatar
0 votes
2 answers
126 views

I was going through the answers to this question Why is it allowed to omit the first dimension, but not the other dimensions when declaring a multi-dimensonal array? and some other questions as well ...
Vinay Yadav's user avatar
  • 1,346
1 vote
3 answers
273 views

The following statement declares a function which takes no argument and returns a pointer to an integer array. int (*f())[]; It returns a pointer to an integer array of size _____ We didn't specify ...
Vinay Yadav's user avatar
  • 1,346
1 vote
2 answers
271 views

In some starter code we have: /** * RGBTRIPLE * * This structure describes a color consisting of relative intensities of * red, green, and blue. * * Adapted from http://msdn.microsoft.com/en-...
DCR's user avatar
  • 15.8k
0 votes
1 answer
47 views

I think I am missing something critical and I can't find an answer. If I want to use string in struct, is it better to use char arrays or pointers to them? Following code works as intended, but raises ...
Swajn's user avatar
  • 1
1 vote
1 answer
103 views

Before C99, does the C standard allow defining or casting to pointers to arrays of length determined at runtime? I understand that the standard doesn't allow variable length arrays before C99, but ...
Puk's user avatar
  • 225
1 vote
2 answers
1k views

I want to swap two rows of a 2d array defined as bellow. double (*mat)[N]; mat = (double(*)[N])malloc(m*sizeof(double [N])); ... swap(mat, mat+1); But my swap(mat, mat+1); only swaps ...
Andrei Bacaoanu's user avatar
1 vote
3 answers
142 views

In the following C code: char test[] ={'T','e','s','t'}; printf("%d\n",test == &test[0]); // Returns 1 - Okay as array varaible holds address of first element So shouldn't the following should ...
lynxx's user avatar
  • 614
1 vote
2 answers
2k views

recently moved from C# to C++ so I'm new to pointers and references and so on. I've a pointer-to-pointer array declared like this enum Type { Void, DeepWater, Water, ... etc } Tile::...
Anthony's user avatar
  • 301
0 votes
1 answer
254 views

I can't understand why this piece of code which is supposed to perform matrix multiplication goes wrong. Input: 2x2 matrices with elements 1,2,3,4 in both matrices Expected output: 7 10 15 22 ...
Manogyana T's user avatar
2 votes
1 answer
178 views

In the following pointer to array, int x[5] = {1}; int (*a)[5] = &x; what implications and consequences can i have if i don't use & operator and do like this.. int x[5] = {1}; int (*a)[5] = ...
Armaan Saxena's user avatar
2 votes
2 answers
1k views

I have a bunch of structs, each of which has an 'array' member and a size indicator: struct S { size_t num; int arr[100]; }; struct V { float array[10]; int size; }; I want to create ...
Benji Mizrahi's user avatar
3 votes
2 answers
148 views

I have 2-D array char arr[2][3]={"sam","ali"} and pointer to this array char(*ptr)[3]=arr; How can I use this pointer to print arr[2][2] which in this case is i. I've tried * (*(ptr+1)+2) the same ...
Mohamed Moustafa's user avatar
2 votes
2 answers
101 views

#include<stdio.h> int main(void) { int arr[5]={1,2,3,4,5}; int (*ptr)[5]=&arr; printf("ptr=%p\n",ptr); i am not getting the diff btw both statements printf("*ptr=%p\n",*ptr);...
sam1006's user avatar
  • 103
-1 votes
1 answer
54 views

This is C code snippet: int main() { char *names=[ "tom", "jerry", "scooby" ]; printf("%s", *names[0]);// prints t printf("%s", *names[1]);// prints j // how to print full word "tom", or ...
ashley's user avatar
  • 57
3 votes
0 answers
105 views

Give the following source (main.c): void foo(const char (*pa)[4]) { } int main(void) { const char a[4] = "bar"; foo(&a); } ... compiled with GCC (gcc (Debian 4.9.2-10) 4.9.2) and run under ...
alk's user avatar
  • 71.2k
0 votes
1 answer
143 views

I am new to learning about C, so as an exercise I attempted to create a text-based card game where each person/CPU places down a random card at the top of their deck, and the person with the higher ...
iRove's user avatar
  • 562
0 votes
2 answers
2k views

I am trying to make an 'int** arr[5]' the each cell in it contains an 'int* array', each 'int* array' has a different size. Whenever i am trying to print one of the cell it prints only the first ...
Yazen Vid's user avatar
3 votes
1 answer
601 views

Here is a C program in textbook, it asks a 3*5 2D array from users and prints the third line. I am confused with int* p[5]. Why here needs to have [5], I think just int* p is OK. It can repeatedly ...
Jennifer Q's user avatar
2 votes
0 answers
94 views

I have 5 different 2d Arrays in contrast to the normal usage of 2d Arrays. int A[1][2] = {2, 5}; int B[1][2] = {6, 1}; int C[1][2] = {4, 8}; int D[1][2] = {3, 6}; int E[1][2] = {9, 7}; Then I have ...
Mohammad Sohaib's user avatar
0 votes
1 answer
199 views

My question is related to my previous post: explicit specialization: syntax error? I am trying to pass arrays of pointer-to-chars as an argument to a function (which I will later incorporate to a ...
mi5tch's user avatar
  • 1
1 vote
1 answer
220 views

I have written code below that contains a function with a pointer to a double array of size 3.My problems is this: when I pass the address of pointer to a double variable (that clearly isn't an array) ...
Mehdi's user avatar
  • 47
1 vote
2 answers
59 views

Consider the following case: int **my_array = new int*[10]; What do we assign to my_array here? my_array is a pointer that points to what? Is there any way to iterate through my_array (the pointer) ...
user5241471's user avatar
-1 votes
1 answer
154 views

I have a structure defined as struct new{ int x; int y; unsigned char *array; }; where I want array to be an array which is initialized dynamically based on user input. Inside main function: ...
yguw's user avatar
  • 864
2 votes
6 answers
102 views

I was reading more about arrays vs pointers in C and wrote the following program. #include <stdio.h> int arr[10] = { } ; typedef int (*type)[10] ; int main() { type val = &arr ; ...
Pratik Singhal's user avatar
0 votes
2 answers
101 views

I have created a function that returns a pointer to an array of strings. The function should traverse a linked list and it should assign the data from each node into an array of string. Here is my ...
lopezdp's user avatar
  • 1,609
3 votes
1 answer
342 views

I want to do something like: const int N = 10; void foo (const int count) { int (* pA) [N][count] = reinterpret_cast<int(*)[N][count]>(new int[N * count]); ... } But my compiler (VS2010) ...
user1234567's user avatar
  • 4,371
-5 votes
7 answers
92 views

If I define an array arr[] and define a pointer to it: int *p=arr; If the value of arr (in terms of address) is 0x1234. What will be the value of p? Will it be the same?
cst's user avatar
  • 53
2 votes
1 answer
160 views

I am writing a C function so that when called, the function would return an array (vector) of the first p prime numbers(with p given from the keyboard in main). My problem is when I try to call the ...
radu-matei's user avatar
  • 3,520
-1 votes
2 answers
115 views

Quick question guys, I have the following issue: I have an Object (struct) pointer in my code, and when I modify something, to keep track of its history, I'm saving it in a vector (stack) of Objects. ...
PedroFaria's user avatar
1 vote
4 answers
108 views

Consider the following code #include<stdio.h> void main() { int s[4][2] = { {20,1}, {21,2}, {22,3}, {23,5} }; int (*p)[2]; int i,...
Blessen George's user avatar
2 votes
3 answers
228 views

#include<stdio.h> #define SIZE 3 int main() { char intArrayOne[SIZE] = {'A', 'B', 'C'}; char (*ptrToAnOneDimArray)[SIZE] = &intArrayOne; int i = 0; for(i=0 ; i<SIZE ...
user366312's user avatar
  • 17.5k
0 votes
0 answers
34 views

How would I go about copying the content of a pointer to an array to a temporary pointer to an array, and then making the original pointer point to the same thing the temporary pointer is pointing too?...
manofZEAL's user avatar
4 votes
3 answers
246 views

I have this code: #include <stdio.h> int main() { int arr[10] = {0}; int *p1_arr = arr; int (*p2_arr)[10] = arr; // Line 7, Shows Warning here ... return 0; } On ...
0xF1's user avatar
  • 6,156