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
-
0
votes1
answer110
viewsI need an explanation why the C code gives a Segmentation fault error
I started my dynamic allocation studies but I’m not able to make a simple example, I couldn’t find the problem. #include <stdio.h> #include <stdlib.h> #define SUCESSO 1 #define FALHA -1…
-
0
votes1
answer793
viewsHow to check whether the list is empty or with an element in C
typedef struct { int tamanho; nodo *inicio; } lista; typedef struct { lista **vet; int tamTabHash; int colisoes; } tabHash; tabHash…
-
0
votes1
answer1497
viewsHow to edit data from a Struct using a function
I want to create an edit function that takes as a parameter the music array by reference. (using pointers) The user must choose the song number and type back the data from that vector position. I…
-
0
votes3
answers176
viewsDynamic allocation with a void function
I made a simple code using dynamic allocation. Just ask for the vector size, to insert data and print them at the end I can make dynamic allocation with int, returning the vet, but as I’m learning,…
-
0
votes1
answer549
views -
0
votes0
answers85
viewsMemory junk when pointing a pointer
In an attempt to implement an adjacent matrix graph, I created the function to create a new "matrix" in which the contents of the graph would be copied to it by adding the new positions. However,…
-
0
votes1
answer38
viewsThe queue code has an error in the search. How can I fix it?
I use the search twice in my code and it is a binary search in order to respect the criteria imposed in the header of this exercise. But the doubt lies in the binary search module because the…
-
0
votes1
answer90
viewsProblem with Segmentation fault with whole pointer
The program below attempts to reproduce a cellular automaton model. When I use "n" (number of cells) above 65 thousand, the program returns Segmentation fault. I tried to "print" some text in…
-
0
votes1
answer57
viewsAccessing methods of a class on a vector of pointers
All right, I have a Package class with a public method double calculate_cost(). I need to create a std::map<string, std::vector<Package*>> where I can iterate through the array and save…
-
0
votes1
answer88
viewsError referencing Struct with Pointers
I’m trying to convert this below algorithm into c language but I’m having trouble calling the variable and assigning a value to p.key=1 of the struct element. Error Code: error: request for Member…
-
0
votes2
answers981
viewsChange a text value using a C pointer
I need to change the values of the variables through their pointers but I’m not getting. #include <stdio.h> #include <stdlib.h> //Programa principal int main() {//Declaração de variáveis…
-
0
votes1
answer84
viewsReturn malloc to pointer does not stay between functions
I have these two examples here: example 1: void copiaStr(char *a,char *b){ b = (char *) malloc(strlen(a)); for(int i = 0; i < strlen(a) ;i++){ b[i] = a[i]; } } int main(){ char *a = "alou"; char…
-
0
votes2
answers37
viewsRedefining how a function operates? C
Hello, I have a question regarding a line of code below, see: #include <stdio.h> typedef float (*TPonteiroFuncao)(float, float); // O QUE ESSA LINHA FAZ? float soma(float a, float b){ return…
-
0
votes2
answers2087
viewsProblem with perfect number in C
I’m having trouble showing if the number is perfect, when I put in 6, it says it’s not perfect, and I can only use pointer and dynamic allocation. Someone would know how to help me? #include…
-
0
votes1
answer559
viewsRequest for Member 'name' in Something not a Structure or Union - Error
#include <stdio.h> #define MAX_VETOR 6 const int na = 1; typedef struct { char nome[10]; char sexo[1]; } tp_pessoa; typedef struct { tp_pessoa *pessoas[MAX_VETOR]; int inicio,fim; } tp_vetor;…
-
0
votes0
answers43
viewsI got an error trying to create my matrix. Error: Warning Passing argument 1 of " " from incompatible Pointer type
I’m trying to create a code with a 3x3 matrix. However, I haven’t touched C for a while and I needed to review this content. I believe that the failure of the program is some question related to…
-
0
votes1
answer73
viewsWhy are the values of x and v[0] not equal? - C language
I’m reviewing some concepts on the site : Addresses and Pointers, until I find the following code: void func1 (int x) { x = 9 * x; } void func2 (int v[]) { v[0] = 9 * v[0]; } int main (void) { int…
-
0
votes1
answer33
viewsList code not compiling well
Hello. I’m trying to learn about pointers and lists and I made a code that contains a menu and the option to enter as many values as I want. I made the code in the most recent codeblocks using W10…
-
0
votes1
answer621
viewsVoid pointer in C
Write a program in C that reads 2 numbers (integer or real) and prints their sum. The user informs what type of data will be entered. Note: Use only pointers and dynamic memory allocation to solve…
-
0
votes2
answers249
viewsProblems with CRUD in C (DELETE method)
In the delete function, the user will inform an AR that he wants to delete, when the AR exists in the memory he deletes, that part of the code works... The problem is when it does not find in memory…
-
0
votes3
answers189
viewsFunction to print the number of characters in a two-dimensional string
By the enunciation of the exercise, I must use as the second argument char **strings, I believe that there is my confusion, in manipulating her to count the size of string. (I did other tests with…
-
0
votes0
answers173
viewsError Segmentation fault(core dumped) in C
When trying to calculate which prime can make a division of rest 0 with the number 600851475143 I came across the error segementation fault(core dumped) (although I used the sieve of Eratosthenes…
-
0
votes1
answer204
viewsHello, I’m trying to do a data structures exercise in c, but there’s an error and I can’t find it. Follow the statement and the code
4. Write in C a system for enrollment and visualization of students. /// To store all students, implement a dynamic vector of pointers for structs, with a size of 100 records #include<stdio.h>…
-
0
votes1
answer35
viewsSegmentation failure using realloc function
Hello, I have a function that should receive values from an intersection and if you enter a value I should relocate more memory and return this pointer. Analyzing the problem, it seems to me to be…
-
0
votes1
answer51
viewsVector pointer with dynamic allocation in C
I managed to do this exercise inside main, however the same concept has not worked when using functions. The aim of the program is simple, read six values and display them. #include <stdio.h>…
-
0
votes1
answer50
viewsSegmentation failure - C
#include <stdio.h> #include <stdlib.h> #include <string.h> int validaTipo(char t); typedef union{ struct contratoIndividual{ unsigned int…
-
0
votes0
answers41
viewsBug in AVL tree implementation
I’m trying to implement an AVL tree, but when I call the Inserts function in the main and step some value(int) happens something strange. The first time the if (of the Inserts function) is…
-
0
votes1
answer297
viewsC CHAR reading that works with %s but not with %c, why? And how does INCREMENT work on a pointer?
I hosted the code complete in the Pastebin: https://pastebin.com/feKaxAiz. It is a matrix where it is possible to perform the SUMMING UP or AVERAGE of the elements above the MAIN DIAGONAL. It is…
-
0
votes0
answers103
viewsC Pointer Vector Search
Consider a type that represents an employee of a company, defined by the following structure: typedef struct funcionario Funcionario; struct funcionario { char nome[81]; // Nome do funcionário float…
-
0
votes1
answer51
viewsStack algorithm problem in C (Struct and function do not "recognize")
Hello, I’m starting in the study of data structures and one of the algorithms passed is for data increment in a vector as in a stack (ie, the last incremented is the first to come out) I am in the…
-
0
votes2
answers40
viewsRelate a user input to a class pointer
I would like to relate the class pointer corresponding to the user input and present on the screen the attributes related to that object. #include <iostream> #include "classes.h" using…
-
0
votes0
answers30
views"Dereferencing NULL Pointer" error in a chained list structure
My code deals with a simple endadeada list (then I will implement the pointer to turn double). But in the line strcpy_s(new_element->musica_name, musica_name); He keeps giving an…
-
0
votes1
answer36
viewsDelete queue element and release memory for this function?
I’m starting to understand pointers better and I’m implementing a queue, and it follows the function: FILA *removeNodeFIFO(FILA **raiz) { FILA *aux = *raiz; if (aux == NULL) { return NULL; } else {…
-
0
votes1
answer35
viewsCan someone help me? I need to write a "reverse" function that reads the inverse of the vector using pointers. Example: typed 123, printed 321
#include <stdio.h> #include <stdlib.h> void inverte (int *original, unsigned int qtd, int *invertido){ } int main() { int qtd; int…
-
0
votes2
answers152
viewsOrdering values by pointers
Good, I was doing an exercise that asked to read 3 real numbers, order them and show in an orderly way. I thought making a function that uses pointers would be a good idea, but the program always…
-
0
votes1
answer48
viewsin C. I passed a vector to a function and changed it inside. Why didn’t you change my vector in the main function? because I passed a pointer
#include <stdlib.h> void matriz_transposta( int l, int c, int *matriz); int main (void){ int linha = 2, coluna = 2; int *mat = (int*)…
-
0
votes1
answer222
viewsPrint array of names in C++
I’m having trouble printing an array that has as elements a char 'Name' saved. When I print these elements, only the last letter of the char leaves, in this case, the letter 'and', and not the whole…
-
0
votes1
answer61
viewsCall function to allocate vector in C
Hello, I’m creating a program to call a function that should allocate a vector to be used in main(), but I’m having difficulty, I imagine I should use a pointer to pointer, but I don’t have much…
-
0
votes2
answers77
viewsMemory allocation with malloc()
Doubt 1: The pont should reserve a memory block for 1 integer which was requested on malloc(), but he reserves 32 bytes or a memory block for 8 integers. 'Cause he does it? Doubt 2: If I make one…
-
0
votes0
answers27
viewsPointer matrix with no type and variable size in C
I am creating a game for my college work and need to read a txt file to build a level (phase) of the game. The txt example can be accessed here: https://pastebin.com/f778Ucxa. The dash represents an…
-
0
votes1
answer56
viewsHow do I pick up two values obtained in a function through pointers?
I am building a program, whose enunciation is to make the user provide 20 numbers and these are analyzed as pairs or odd. In this case, the intention is to create a vector A that takes 20 integers…
-
0
votes1
answer65
viewsHow to pass a char vector * (*) to a function?
Guys, I have this code: #include <stdio.h> void exibir_nomes (char *nome) { for (int i=0; i<5; i++) printf("Nome[%d] = %s\n", i, *nome); } int main () { char…
-
0
votes1
answer38
views -
-1
votes1
answer49
viewsHelp in function with pointers
Can anyone help me with this code ? not working, can’t find the error. #include <stdio.h> int chamar(int *n){ printf("Digite o valor de n:"); scanf("%d",&n); printf("%d",n); return 0; }…
-
-1
votes2
answers171
viewsAdd a char on a char pointer in C/C++
I need to add a char on a pointer of char. For example: I have a pointer of char called name, which receives "log", after the process, I want it to be "log1". I tried to implement it like this, but…
-
-1
votes1
answer438
viewsHow to pass a pointer inside a struct per function parameter?
The situation is as follows: I have a struct with a field that is a pointer pointer, however I want to pass as parameter in a function only the pointer pointed, that is, the innermost pointer of…
-
-1
votes1
answer317
viewsFunction with pointer to pointer
I have the following function NOTE: In this function is only the first case, so it doesn’t get too big. Since the error occurs right at the first insertion. int insertAVL_TreeR(struct AVL_TreeNode…
-
-1
votes1
answer450
viewsHow to do a pointer struct for a function that prints the struct itself in C
I have a structure: struct conteudo{ tipo valor; //valor qualquer void (func*)(void*); //ponteiro para função que imprime a propria estrutura }; I would like to know how to call this function to the…
-
-1
votes1
answer28
viewsWhy am I making a mistake adding two numbers using pointers?
#include <stdio.h> int* adicionar(int *a,int *b) { int c = *a + *b; return &c; } int main() { int primeiro, segundo; int* temp; scanf("%d%d",&primeiro, &segundo); temp =…
-
-1
votes2
answers64
viewsIncrement does not work as expected
I took this exercise and put it to compile, but it’s going wrong I think because the values I see would be 5 and 9, but it’s going 6 and 8, I believe the IDE is not reading correctly. #include…