All Questions
30,367
questions
2
votes
1
answer
114
views
array of pointers to pointers to integers VS pointer to pointer to array of integers
I have 3 integers A, B & C from which I make pointers that I group in an array arrayABC of pointers to pointers:
int A = 1;
int B = 2;
int C = 3;
int *ptA = &A;
int *ptB = &B;
int *ptC = &...
1
vote
0
answers
39
views
Passing an array to a function in C - array subscript vs pointer dereferencing [duplicate]
Coming from mainly Python and JavaScript
I (think I) understand that when you pass the name of an array to a function, the array is decayed to a pointer. The part that confuses me is the fact that the ...
1
vote
1
answer
149
views
Can't understand this C syntax. Designated initialization of an array of structs?
Trying to learn the nuances of C, though I was doing well until I found this:
#define SOKOL_IMPL
#define SOKOL_GLES3
#include "sokol_gfx.h"
#include "sokol_log.h"
#include "...
2
votes
3
answers
123
views
Converting to char*** from char* [2][2]
I have the following variable
char* a[2][2] = {{"123", "456"}, {"234", "567"}};
I wanted to refer it using another variable. While the cast works, accessing ...
1
vote
3
answers
101
views
In C, why can a variable holding a char array be assigned to a pointer, but the address of the same pointer cannot?
Consider the following code:
char stringy[] = "There's too much confusion, I can't get no relief!";
char *pStringy;
pStringy = stringy;
This compiles -
stringy is an array of characters, ...
-1
votes
0
answers
43
views
I need help reversing an array in C [duplicate]
Hey I'm a beginner to C so please excuse any beginner mistakes I make on this platform.
I am trying to write a program that reverses the order of the elements elements of an array and prints it. I ...
0
votes
2
answers
61
views
Is the & operator is essential to use as address operator [duplicate]
#include<stdio.h>
int main()
{
int a[5]={5,10,15,20,25};
int *p;
int i;
p=a;
for (i=0;i<=5;i++)
{
printf("the address of the %d is = %d\n",*p,p);
...
-1
votes
1
answer
93
views
write a programme in c to skip 2 elements after occurence of a non prime
I write the code as my knowledge but i didnt get the correct ouput.i provide my code below
#include <stdio.h>
int main() {
int i, j, isPrime, n, a[1000], k;
// Input array limit
...
0
votes
0
answers
17
views
Initializing an array created with malloc with arbitrary values
I need to create large float arrays using malloc, to be able to free the memory when I don't need the array anymore.
The values are arbitrary, meaning they are not all zeros or ones, much more random ...
-3
votes
1
answer
84
views
Why does incrementing a pointer to an array give this result?
If I define a new (int) array, and increment the dereferenced pointer to this array by 1, why do I get the following result?
int main()
{
int myArray[1024];
myArray[0] = 123;
myArray[...
0
votes
1
answer
62
views
Why does my C program with any input results in segmentation fault?
I've spent hours of racking my brain on why doesn't this work
#include <stdio.h>
#define MAXLINE 1000
#define TRUE 1
#define FALSE 0
int getLine(char s[], int lim);
void copy(char to[], char ...
0
votes
0
answers
29
views
unable to take input of strings from user [duplicate]
I have to make an array of structure for cricketers presenting their name, age etc. and take input of each value from user . I am trying to get value of name from the user but my code editor keeps on ...
2
votes
3
answers
103
views
Do brackets have effect during array of pointers declaration?
Recently I was reading "The C programming language" text book by Brain and Dennis and encountered that there is a difference between the pointer array definitions shown below:
int (*a)[10];
...
0
votes
0
answers
38
views
How do I dynamically allocate memory for a multidimentional array in C? [duplicate]
Dynamically allocate memory for a multidimensional array (matrix) with a specified number of rows and columns.
How to allocate memory?
How to allocate memory for 2D array?
How to dynamically allocate ...
0
votes
1
answer
50
views
How to use `static` with an array of array in C
Given,
int last(int arr[3][6]) {
return arr[2][5];
}
I want to make it clear that arr can't be null with the static keyword.
The problem is that the following code won't work.
int last(int arr[...