Most voted "pointer" questions
The tag can be used for the concept applied to any language. A pointer is a type of data that "points to" another value stored in memory using its address.
Learn more…481 questions
Sort by count of
-
7
votes2
answers595
views"Operator" square brackets [] when creating the arrangement in C
Whenever I look for what the operator clasps [] makes, even in the tables that show all operators in C, appears that it serves to access an element of an arrangement. However, it is not always that…
-
7
votes2
answers212
viewsPointer to struct
I was studying pointers to struct, and I saw that it has two ways to use. can be: (*ponteiro).variavel Or: ponteiro->variavel According to what I read, when we put *ponteiro.variavel, because of…
-
6
votes2
answers942
viewsFunction returns pointer to trash, and free locks the terminal
Could someone explain to me the reason when I give free in the pontaux Windows terminal stops responding? And why when I allocate pontmaior my result comes as memory junk? The function returns a…
-
6
votes2
answers654
viewsPointer logic
In C++, you can do the following: int variavel[10][10]; int** variavel; But when I want to create an array 2d, where I can have the first part "unlimited" and the second part with limit? tipo…
-
6
votes2
answers934
viewsHow to create an index file using B+ tree
I have a B+ tree that acts as the index of a data file. This index must be saved in an index file. A struct node or node of the B+ tree is: typedef struct node { void ** pointers; int * keys; struct…
-
6
votes2
answers475
viewsMalloc improperly reserving memory?
I am studying dynamic memory allocation and came across an error that apparently the compiler is not warning about. The code is very simple: int *ptr = (int *) malloc(sizeof(int)); ptr[0] = 5;…
-
6
votes1
answer123
viewsWhy can I access a structure without the pointer?
When I declare a pointer to struct I can access members without entering an address struct, why is it possible? For example: struct exemplo{ int a ; }; int main() { struct exemplo *p; p->a = 10 ;…
-
6
votes2
answers148
viewsWhy doesn’t the pointer increase the value?
Here was to increase the value of the variable, but it does not work. #include <stdio.h> #include <stdlib.h> int main() { int *p, x = 10; p = &x; *p = (*p)++; printf("%d \n", *p);…
-
6
votes1
answer356
viewsWhat is * for in the expression "Foo* foo = new Foo" in C++?
I was looking into this question done in SOEN. There is teaching to instantiate a certain class. I was able to understand more or less how it works, because when I use my example, it is giving error…
-
6
votes1
answer75
views -
6
votes1
answer90
viewsHow is it correct to declare a variable that is a pointer?
I see some people do int* variavel; And some people do int *variavel; What is right?
-
6
votes3
answers137
viewsAccess to pointer on main
Why in the statement as argument in function main(): char* argv[] instead of char argv[] i can access the information. I know one is pointer. I can’t access when it’s not pointer. #include…
-
6
votes2
answers140
viewsIs Array a C pointer?
I am reading a book about C pointers, but as I am new to such a language, still for me the concept of pointers is a bit complex, and when reading the following definition, I came to the question…
-
6
votes2
answers146
viewsPointer changes address when exiting function
When performing a dynamic allocation of a vector or matrix in C, the pointer for that allocation changes address when leaving the function, before it was pointing to the initial address of the…
-
6
votes1
answer132
viewsAre variables randomly allocated in memory?
In a book about C, in which I started studying variables, it said that variables were randomly put into memory, for example: int a; int b; printf("a = %d\n", &a); --> 5000 (endereço) (%d ao…
-
6
votes1
answer169
viewsIntelligent Pointers
I was studying smart pointers and based on this blog: https://murilo.wordpress.com/2008/12/15/smart-pointers-os-ponteiros-espertos-do-c/ #include <iostream> template <class T> class…
-
5
votes1
answer139
viewsPrecedence of operators with pointers
Having, for example, the following instructions: int i=10, j=20; int *pti, *ptj; pti = &i; ptj = &j; What is the meaning of j = pti == ptj; and of i = pti || ptj; ? Also, I read that the sum…
-
5
votes2
answers912
viewsHow to free memory from an internal malloc to a function that returns a pointer?
How to release a malloc internal to a function that returns a pointer? In a simple way to try to exemplify my doubt, consider the following function f: int *f(int tam) { int *ptr = malloc(tam *…
-
5
votes4
answers456
viewsMemory allocation for pointers
I’ve been reading and studying on pointers and came across the following quote in a book: "Although it is possible to use them as vectors, pointers do not have their own memory. You can only use…
-
5
votes1
answer169
viewsSpecial treatment for string, why?
I know arrays are static elements used when you have a predetermined size that you can use. But speaking of initialization, when the size is already set next to the array, I would like to know,…
-
5
votes1
answer459
viewsWhat is a shared_ptr?
If possible, with an example of code, as this is missing in the reference to really understand when and how to use the shared_ptr.
-
5
votes1
answer1901
viewsHow to use realloc() dynamically in struct allocation?
I have a structure struct TMedidorEletrico *medidor;, and it is necessary to reallocate the memory to this structure dynamically, until the user closes the loop. Memory must be reallocated one step…
-
5
votes2
answers1808
viewsAssign a value to the pointer and multiply (directly)
How do I multiply the pointer so I assume a value to it? #include <stdlib.h> #include <stdio.h> int main (void) { int a,*b,*c,*d; printf ("\nInforme um valor: "); scanf ("%i",&a); b…
-
5
votes2
answers393
viewsIf array is the same as pointer, why does one need to be copied to a variable and another need not?
In that reply Maniero said that if the member of the structure was a pointer it would not need to copy the string into it. But arrays are not pointers? Why is it different?…
-
5
votes2
answers866
viewsChar pointer or char array?
There’s a program that I picked up at a company, where pointers are used to char, guy char*, and then allocated a memory for it with the malloc, done the operations and at the end de-located that…
-
5
votes1
answer476
viewsWhy use pointers as function parameters?
I already have a certain knowledge about pointer, but I wanted to understand why in most cases people use pointers as parameters in functions. Currently I have been studying algorithms through the…
-
5
votes1
answer97
viewsStrange values in output when running newly compiled application
When I compile and execute this code on Linux, it shows a strange result. I believe it is memory junk. What is happening for it to show this result, and how I can solve? Command lines to compile…
-
5
votes2
answers9758
viewsPass matrix as pointer
I need to make the proposal: Elaborate a function that takes as parameters a pointer of an array, the number of rows and columns, and print the matrix elements. But I am learning pointers and having…
-
5
votes1
answer123
viewsWhy is it possible to store a string on a char pointer?
Why char stores a single character and the pointer points to its value in memory, so it shouldn’t have just one character? Example: char *str = "Ola"; Why str does not store only one character?…
-
5
votes1
answer732
viewsPointer pointer to change my battery. Why should I use them?
I am making a code that consists of analyzing an arithmetic expression, and checking if when I open a '(', then I must close a ')'. That is, check whether the expression is valid or not. For this I…
-
5
votes1
answer210
viewsWhat is the difference between %p and %d in C language?
Which means the memory address that appears with %p and the %d exactly? What’s the difference? int main() { int teste = 10; int *ptr = &teste; printf("%p\n%d",ptr, ptr); return 0; }…
-
5
votes2
answers97
viewsWhy can’t I access the array of integers in the main() function?
I cannot access the positions of the vector of integers that I loaded in the function loads. In that function I can correctly access the data with: printf("%d\n", n[i]); But in function main(),…
-
5
votes3
answers1148
viewsDynamic allocation in C - allocating without knowing the total amount of elements
I have a question about the dynamic allocation in c, as to the use of the function malloc(). If we take, for example, a case of registration of a full name, as we have no way of knowing the amount…
-
5
votes3
answers182
views -
4
votes1
answer398
viewsWhat is the difference between these ways of indexing a pointer to an array of structs in c?
Is there any difference in the use of these 3 statements? void addCliente(struct cliente *dadosCliente){ dadosCliente[k].nome="oi"; (*(dadosCliente+k)).nome="oi"; (dadosCliente+k)->nome="oi"; }…
-
4
votes1
answer437
viewsPointers with methods, where am I wrong?
Creating a class that will have two methods one assign another to print vectors with public and then call this method no main. I was able to make it this far with the method baby Steps. Where I’m…
-
4
votes1
answer81
viewsQsharedpointer Definition and Function
From what I understand, the Qsharedpointer is a smart Pointer, ie, a pointer that offers automatic garbage collection. If possible I would like a code that better explains this, including when I…
-
4
votes1
answer329
viewsPointer of struct in C
What happens is this, within the function ins_ult() I can change the value of root->data, but outside the function the value remains NULL. I’m passing the parameter the wrong way or using the…
-
4
votes1
answer523
viewsIs it possible to use pointers in VB.NET?
Is it possible to use VB.NET pointers? If so, how do they work? An example in C++: CSR = ConfigurarInterfaceDeRede(randInt(0,999999),CodAtivacaoSAT,(char*)xml); int a; int *p; p = &a; How would…
-
4
votes1
answer341
viewsUnderstanding pointers
I’m trying to learn C++ on the Internet, I understand more or less what pointers are but I don’t see a utility, I don’t know anything about C++ I just don’t want to go over this subject, I did a…
-
4
votes2
answers815
viewsWhy declare pointer to array if arrays are already pointers?
if an array char is already a pointer, why declare a pointer to the array? And what’s the difference between char exemplo[10] and char *exemplo[10]?
-
4
votes2
answers260
viewsDoubt about pointers
This code creates matrix, initializes and prints, as well as adding, subtracting and multiplying matrices: typedef struct{ int nl; int nc; int **elementos; }MATRIZ; void criar_matriz (int, int,…
-
4
votes1
answer229
viewsSegmentation fault when accessing pointer content
I need to declare a pointer vector, which will point to types float, and make a simple reading of values. The program compiles but after typing 4 values I get a Segmentation fault (core dumped). Why…
-
4
votes1
answer84
viewsWhat good is C-EPERM?
What is the purpose of the -EPERM, after comparing the pointer p is null if(p == NULL) return -EPERM ; And I have to put these two libraries. #include <errno.h> #include <stddef.h>…
-
4
votes1
answer94
viewsNested pointers and references
I’m having a doubt in the interpretation (the way I read my code) on pointer assignments in the C language. I did not understand the logic of the following assignments: "If i and j are whole…
-
4
votes1
answer442
viewsCopying string stored in pointer
What is wrong? #include <stdio.h> #include <string.h> int main(void) { char *str= " teste"; int j = 0; while(str[j] == ' ') j++; memcpy(str, &str[j], strlen(&str[j])+1);…
-
4
votes2
answers69
viewsHow should these variables end correctly without having a chance of memory Leak?
What is the right way to use the free() in that case, where ls_options will contain several ls_buffer_send? char **ls_options = (char**) malloc (200*sizeof(char)); char *ls_buffer_send = (char*)…
-
4
votes1
answer152
viewsTyping a pointer to struct
I was suggested to build a chained list using the following struct knotted: typedef struct node *link; struct node{ int item; link next; }; As I did not understand what the pointer operator means…
-
4
votes2
answers117
viewsHow do I use free() and return the same content?
I wanted to use the free() in ls_retorna in the following function, how could you do it with the best way? char* MemCpyX(char *as_origem, int an_inicio, int an_quantidade) { char *ls_retorno =…
-
4
votes3
answers408
viewsUse free() without malloc()?
May cause some problem in using the free() on a pointer that was not allocated with malloc() beyond the necessity itself? void funcao (int par) { char *palavra; if(par%2 == 0) { palavra =…