Skip to main content
Filter by
Sorted by
Tagged with
-2 votes
3 answers
187 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
176 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
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
0 votes
0 answers
1k views

I have an aggregation like this : this.collection.aggregate([ { "$match": { _id: id } }, { "$addFields": { "self&...
Sara's user avatar
  • 5
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
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
2 answers
645 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
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
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
1 vote
3 answers
264 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
0 votes
1 answer
38 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
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
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
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
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
-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
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
3 votes
1 answer
599 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
0 votes
1 answer
194 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
2 answers
57 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
2 votes
6 answers
100 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
3 votes
1 answer
336 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
2 votes
1 answer
155 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 vote
4 answers
107 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
0 votes
0 answers
33 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