Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
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 = &...
Steens's user avatar
  • 128
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&...
cutelittlebunny's user avatar
-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 ...
Vishvanathan K's user avatar
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 ...
bytecafe's user avatar
-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 = &...
SakSath's user avatar
  • 145
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 ...
Sreepathy's user avatar
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='...
Rajesh Paul's user avatar
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 &...
k1r1t0's user avatar
  • 735
-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 ...
ASHNA A's user avatar
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, ...
Bennypr0fane's user avatar
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); ...
khushal dak's user avatar
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 ...
shown zhang's user avatar
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? ...
Catstail's user avatar
-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[...
evstack's user avatar
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 &...
gilfoyle's user avatar

15 30 50 per page
1
2 3 4 5
1888