All Questions
28,310
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
1
answer
28
views
Can't put values together into struct that is initiated by pointer and malloc [duplicate]
Just a simple struct called person, inside I need to store name and age. I'm trying to dynamically allocate memory for my struct.
Without using pointer:
#include <stdio.h>
#include <stdlib.h&...
-3
votes
0
answers
122
views
Are pointers smartly allocated? [duplicate]
While learning about pointers in Uni, They taught us that pointers are allocated memory for the address to be stored. And while I was messing around with pointers and null pointers.
I noticed this ...
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 ...
-2
votes
0
answers
95
views
Pointer "ptr + offset" vs "&ptr[offset]" [closed]
Consider a piece of code in C as shown below
int arr[1000];
int offset = 500;
int *ptr_array = (int *)&arr[0];
int *ptr_temp1 = ptr_array + offset; // ---> method-1
int *ptr_temp2 = &...
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 ...
0
votes
1
answer
114
views
Why does defining the elements of the array b is required to get the desired output
I recently learnt about typecasting pointers. So I played around, and made this bad code:
#include <stdio.h>
int main()
{
int* a;
char b[]= "Hye";
a = (int*)&b;
*a='...
2
votes
1
answer
107
views
Is comparing two pointers to different char objects undefined in C?
This is code of memmove from https://github.com/gcc-mirror/gcc/blob/master/libgcc/memmove.c
void *
memmove (void *dest, const void *src, size_t len)
{
char *d = dest;
const char *s = src;
if (d &...
-6
votes
2
answers
71
views
malloc(): corrupted top size on deleting an entry from binary file [closed]
I AM CREATING A SCHOOL MANAGEMENT SYSTEM . WHEN I TRY TO DELETE A STUDENT AFTER ADDING ONE I AM GETTING "malloc(): corrupted top size" ERROR .CANT FIND THE REASON.I AM A BEGINNER , HELP ...
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, ...
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);
...
0
votes
2
answers
130
views
In C language, the first character of a string variable is 0, but when printing, 0 disappears?
I am a beginner of C language. I wrote the following code to convert uppercase letters to lowercase letters and copy them to a new variable. Variable c2 was only declared and initialized, but when ...
2
votes
1
answer
66
views
Is an asterisk needed when specifying a function pointer?
I can specify pointer to function in C code as follows:
double foo (double f (double), ... other parameters )
or
double foo (double (* f) (double), ... other parameters )
What is the difference?
...
-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
2
answers
111
views
GCC compiler handles "char * str" and "char str[]" with the & operator differently [duplicate]
The compiler treats the types char * var and char var[] differently when it comes to taking the address of a variable via the & operator. Here's a little snippet of code to demonstrate:
#include &...