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
-
4
votes1
answer592
viewsLarge switch case in C
I am developing a system for the college and I would like to know what is the best option, in the sense of optimization of the code, of improving even. I have a switch Menu case, where I have 88…
-
4
votes1
answer149
viewsWrite list in binary file
The idea of this method is to write all the words of a list of nodes in a binary file. I have a linked list of nodes, where each node has two information, its information, and a reference to the…
-
4
votes1
answer1523
viewsCorrect use of free() in function?
How to use function free() when it is used within a function, in that function Gero a dynamic vector and the function itself will be the return, example: int* copia(int *vet, int tam) { int i,…
-
4
votes3
answers315
viewsHow to access a pointer within a structure?
I need to know how to access the first position of the pointer vector *c_parte_real, as shown below: typedef struct{ struct char_vector{ char *c_parte_real[2], *c_parte_imag[2]; }c_vector; struct…
-
4
votes1
answer135
viewsWhy does a parameter have two "const" in its statement?
I’m reading the tutorials on the website of lib Opencv and during reading I saw the declaration of a function with a variable in a format I’ve never seen. I wanted to know what it means, declare the…
-
4
votes1
answer2537
viewsWhat is the difference between pointer to vector and pointer to variable?
int A; int* pA = 1; int Vect[2] = {1,2}; int* pVect; pA = &A; *pA = 2; pVect = Vect; pVect[0] = 10; In the case I have a pointer to a variable and then to an array, and I want to change its…
-
4
votes4
answers715
viewsWhat’s wrong with the c-code?
The task: Pedrinho and Zezinho need to study solving mathematical expressions for a test they will do. For this, they want to solve many exercises before the test. As they know how to program, so…
-
4
votes1
answer7212
viewsPass Array as a function parameter
Make a program in C that reads a value x, dynamically create a vector of x elements and pass this vector to a function that will read the elements of this vector. Then, in the main program, the…
-
4
votes2
answers625
viewsCalculate the factorial by reference passage
I’m studying pointers I’m trying to calculate a factorial of a number, only the result comes out a totally different value than expected. Here is my code #include<stdio.h>…
-
4
votes1
answer1747
viewsFunction to sum elements of an array does not return correct value
I am making a program for a shopping list, the user passes to the program the values of each product and each one is stored in a vector. Then we added the elements of the vector to give the total…
-
4
votes1
answer239
viewsHow do I get rid of these warnings
I’m doing a program that hunts a word from a matrix. For this I made 8 functions that sweep in all regions, as I need to return in the output the coordinates of the first and last letter. For…
-
4
votes3
answers7927
viewsDoubt about Struct and Pointer for Struct
I’m having doubts in my code about structs and pointers for structs, the doubts are as follows: 1) Because I don’t need to put (->) before speed, for example ( p->attributes->speed) in…
-
4
votes1
answer410
viewsGolang - Doubt about pointers
I have a struct called Calculator, with two properties: version and author. To be able to instantiate this struct already initiating these methods, since Golang has no constructors, the various tips…
-
4
votes2
answers70
viewsPointer pointing to another pointer, how to use the free() correctly?
When I have a pointer pointing to another pointer like: int *ponteiro1 = malloc(sizeof(int)); int *ponteiro2; *ponteiro1 = 5; ponteiro2 = ponteiro1; free(ponteiro2); And I use the command…
-
4
votes1
answer74
viewsWhat is Clone-on-write (Cow)?
I’m studying Rust and recently discovered the existence of Cow, one smart-Pointer that works to make Clone-on-write. The description of the page seemed confusing to me, since I don’t have much…
-
4
votes2
answers92
viewsWhat term should I use in English for "dereference" a pointer
As you know in English the term Dereferencing is used to indicate access to the value stored at an address stored on a pointer i and..: int valor = 10; int *ptr = &valor; *ptr = 20; //…
-
4
votes1
answer126
viewsWhy am I getting access to this pointer even after I’m free?
I have this program and theoretically it was not to lose the address of new after giving the free making the same inaccessible ? #include <stdio.h> #include <stdlib.h> typedef struct{…
-
4
votes2
answers588
viewsHow do I correctly access elements of a dynamic matrix via pointer?
As many know (I believe) a multidimensional matrix is stored in memory in a linear way, that is, each line of the matrix goes in memory one after the other. To illustrate I elaborated the following…
-
4
votes2
answers106
viewsFunction with a pointer?
Enunciation: A student’s grade is calculated from three grades awarded from 0 to 10 respectively to laboratory, a bimonthly evaluation and a final examination. The average three notes mentioned…
-
4
votes1
answer124
viewsHow abstract are pointers in C?
I have a vision, which from time to time seems wrong, that C pointers are simply and literally memory addresses. In this case it starts from a misconception that memory was a linear thing and…
-
4
votes1
answer38
viewsUse of delete in an abstract class pointer
Reading the book A tour of C++, in a section on memory leakage, when I came across 3 statements regarding the code below: The implementation of Smiley may fail to delete pointer to mouth. The…
-
3
votes1
answer117
viewsWhy can’t I use || for pointer?
I have the following code: int i=0; variable a; a.type = CHAR; a.name = malloc(sizeof(char)+1); while(*l->str++ != ' '); while(*l->str != ';' || *l->str != '='){ a.name = realloc(a.name,…
-
3
votes2
answers276
viewsResize into dynamic pointer turns dimension into garbage
I was responding to an implementation problem of Std::stack. It was easy, but I couldn’t use my first idea: Std::vector (replaced dynamic pointers forever). My code is: template <class T>…
-
3
votes1
answer218
viewsC++ Dynamic Pointer Allocation
I am needing to create a protection routine in the removal function. Why it gives error when removing the last item? The function: // Remover o primeiro cliente void cadRemover(){ lista=ini; //…
-
3
votes1
answer9629
viewsThis error tells: "Return makes Pointer from integer without a cast"
int *aloca_vetor(int MAX){ int i,*vetor; for ( i = 0; i < MAX; ++i) { vetor[i] = (int*) calloc (1, sizeof(int)); } return (vetor); Error: projeto.c:13:15: warning: assignment makes integer from…
pointerasked 10 years, 5 months ago João Carlos 31 -
3
votes1
answer265
views -
3
votes1
answer4892
viewsHow to use the pointer concept in php?
I’m learning about pointer in C language and I already know how to use it. I believe the way to use php pointer is the same in C. But how do I declare php pointer?
-
3
votes1
answer276
viewsIncompatible arguments - Pointers for structures
Good afternoon, I needed help fixing some mistakes at the terminal. Summary: I have done some functions to get some information (values) about active clients (where a client is active if he is an…
-
3
votes3
answers677
views -
3
votes2
answers344
viewsSegmentation Fault (core dumped ) Array reading
I have a problem related to reading a array that produces the error Segmentation Fault (core dumped ) This is only the beginning of code development, but already presents an error after reading the…
-
3
votes1
answer128
viewsWhy can’t I modify the string this way?
When we have a declared int variable, and then a pointer to that variable: int x = 10; int *p = &x; To modify the variable x through the pointer, we have to do: *p = 20; But when I declare: char…
-
3
votes1
answer66
viewsAssign/Print values to void * in a structure
#include <stdio.h> typedef struct elem{ void * d; }Elem; main(){ Elem *p; Elem e; double pi = 3.14; e.d = π p->d = π printf("%f\n",p->d); printf("%f\n",e.d); } When I do…
-
3
votes1
answer107
views -
3
votes1
answer2388
viewsAccess attributes of an object vector of another class using C++ pointers
I am doing a job for the college in which I have to put together a program to manage a restaurant that only makes deliveries the orders are made by phone and internet using object orientation and…
-
3
votes1
answer109
viewsMemory allocation and wiping in C - how much should I worry about?
I’m learning C from the book "Use Your Head! C" (damn me). Given a lesson, I need to create a struct calling for "island" with the following code: typedef struct island { const char *name; const…
-
3
votes1
answer139
viewsIs there a problem with pointers in this struct that works with chained lists?
Hello. I’m developing a game with C++ language and I think I’m making a mistake in using chained lists. I think I know that there are more interesting features than using chained lists in C++, but…
-
3
votes1
answer193
viewsDifference between pointer vector for a class and vector for a class?
When is pointer to class will we have to allocate memory space? What is the difference between the following two statements and when they should be used ? Vector <class*> nameOfVector; Vector…
-
3
votes1
answer94
viewsPointer cannot be reset to NULL within function
Hello, folks! I was studying binary trees and needed to create a function that would remove any knot and its children. However, when I did this function with the return /1/ the node has not been…
-
3
votes1
answer701
views -
3
votes1
answer85
viewsObtaining different results by passing by value and passing by reference
I’m testing these examples of C codes: Call by value #include <stdio.h> /* function definition to swap the values */ void swap(int x, int y) { int temp; temp = x; /* save the value of x */ x =…
-
3
votes1
answer793
viewsPointer from struct to struct
Hello, I had asked a previous question about this problem, however I was able to solve but not learn about the problem itself so I tried to isolate it by creating a specific code for this problem…
-
3
votes2
answers797
viewsWhy can you pass a char vector to the scanf as the direct address or variable?
If the name of the vector or matrix is already the address of the first element, why scanf(), using the primitive types (int, char, float, double) I need to pass the address, being that when we want…
-
3
votes1
answer271
viewsIs there a problem assigning a value to a pointer?
I’m referencing myself by this site here How to declare pointers in C Usually when we want to start an integer type variable, for example, we do int inteiro = 4;but what if we did int *inteiro_ptr =…
-
3
votes1
answer842
viewsWhy does a string assignment in C not work?
I’m having trouble assigning a value to a variable of type char of a struct I’m doing the following #include <stdio.h> typedef struct Animal{ char nome[5]; // indiquei que a variavel nome tem…
-
3
votes2
answers74
viewsWhere is the function that a decayed lambda to pointer points to stored? How is it released?
I learned recently that I can do this: auto a = +[]{return true;}; a = +[]{return false;}; And I understood that a lambda that captures nothing can decay to a pointer for function, as confirmed by…
-
3
votes2
answers240
viewsString pointer does not work as expected
I’m trying to print the pointer of string below, and put yourself " %s " + char* t[]; makes mistake, already put %c he prints the letter " i " I don’t know why. I want to learn and not Ctrl + c and…
-
3
votes2
answers159
viewsWhy is the value in bytes displayed as 4?
I am using a 2x2 matrix with a simple pointer and want to display the values of it. #include <stdio.h> #include <stdlib.h> typedef struct matriz mat; struct matriz { int lin; int col;…
-
3
votes1
answer135
viewsUse of typedef for pointer
If I’ve already set a pointer to my structure why can’t I make the allocation of it. #include <stdio.h> #include <stdlib.h> struct ponto { int a, b; }; typedef struct ponto *Ponteiro; //…
-
3
votes1
answer73
viewsAllocate memory with pointer or reference?
Is there any significant difference between these two methods? MyClass &ref = (*(new MyClass)); MyClass *ptr = (new MyClass);
-
3
votes2
answers205
viewsWhy do some functions that work with C strings start with *?
In one of our classes we were taught that when a function receives as a parameter an array it is actually receiving the memory position in which it is allocated so it is not necessary to return any…