Most voted "struct" questions
A struct or structure is a composite data type consisting of one or more variables grouped under a name.
Learn more…405 questions
Sort by count of
-
68
votes1
answer19312
views -
35
votes1
answer1899
viewsAccess to the DLL library made in Delphi from Java
I am developing a tool for biometric recognition using the SDK provided in DLL format, developed in Delphi. For DLL access from Java, I am using JNA. The digital template (the most important part)…
-
19
votes1
answer941
viewsHow does C/C++ "padding work?
In several responses here at Stackoverflow I have noticed users commenting on padding in data structures. struct { int a; char b; float d; } What is this one padding (filling) that exists between…
-
18
votes3
answers10342
viewsWhat are Unions? Why use them within structs?
I’d like to understand the differences between union and struct. I realized that both can be accessed in the same way: u.membro uPrt->membro s.membro sPrt->membro In practice I have seen…
-
14
votes5
answers13398
views -
12
votes1
answer1922
views -
12
votes1
answer449
viewsWhat’s this 'in' in C#?
In the new version of C#, version 7.3 the parameter changer was introduced in, but I didn’t understand its functionality. By name, it seems that it is used as "input" for the values, contrary to the…
-
8
votes1
answer460
viewsHow to allocate a member of a struct to C?
I wonder if it is possible to allocate a atributo of a struct, follows my struct example: struct MinhaStructExemplo { int * atributo_quantidade; /*Atributo que eu gostaria de alocar na memoria*/ };…
-
8
votes1
answer122
views -
8
votes2
answers291
viewsCan I use class and struct at the same time?
I have a variable "Address", however, it is composed by "Street", "Number" etc. The way I did below is the best to be done? With class and struct at the same time? Or is there something better and…
-
8
votes1
answer110
viewsWhy, in C, is a statically declared array name not an lvalue?
Why, in C, the name of a statically declared array is not a lvalue? A lvalue is an expression that can appear on the left side of an assignment statement. It is an expression that represents a…
-
7
votes1
answer219
viewsStart structure pointer with an address?
I wonder if it is possible to start this structure type pointer with an address, without needing to point to another variable, or allocate memory. typedef struct{ char nome[20]; int idade; }pessoa;…
-
7
votes1
answer72
viewsUse the anonymous typedef or not?
I was looking at some C codes and I came across something like this: Example: typedef struct { char nome[256]; } Pessoa; typedef struct Pessoa { char nome[256]; } Pessoa; There is some difference…
-
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
votes1
answer1411
viewsHow to place variables within vectors?
How do I create variables within a vector? Something like: int arr[] = {int x=1, int y = 2};
-
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
votes1
answer1950
viewsHow do I save a string of indefinite size to a structure?
#include <stdio.h> #include <stdlib.h> #include <string.h> struct Ecoponto{ int codigo; int contentores[3]; char cidade[20]; char *rua; int nporta; }; int main(int argc, char**…
-
6
votes1
answer298
viewsPerformance differences between structs and classes
I know the difference between structs and classes is that structs has its public members by default, and that structs belong to C (but nothing prevents use in C++). In practice when creating an…
-
6
votes2
answers198
viewsstrcpy is merging numeric format with other chars
I don’t know if I made myself clear in the title, but when using strcpy() to copy a char* to another when I put a format like this "teste" it works normally, but when I put a string 3 letter format…
-
6
votes2
answers1288
viewsWhat do "re:" and "im:" mean in Rust?
I want to know what re and im mean/do let mut z = Complex { re: 0.0, im: 0,0 }; I’m learning Rust by the book Programming Rust and this re: and im: it must have appeared before, but only now have I…
-
5
votes1
answer637
viewsHow is a "struct" organized in memory?
How access to struct? Can I put members in the order I want? How does the compiler know which part of the memory to access? What would this look like? struct { char ch1; short s; char ch2; long long…
-
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
votes1
answer98
viewsCan Union and struct be considered operators?
One union or a struct can be considered operators? As well as return, goto and sizeof?…
-
5
votes2
answers90
viewsWhat are these complex members within a struct?
I have a question in a struct on the last lines with uchar and void which is quite different from what I know. Why many programmers use underline in the names of structs, variables etc... struct…
-
5
votes1
answer219
viewsIs it incorrect (or problematic) to create a string array struct?
I’m not sure what’s the ideal way to create a structure (struct) that contains a array of string, in case I have a structure like this: #include <stdio.h> #include <stdlib.h> typedef…
-
5
votes1
answer73
viewsstruct character array
I’m having to remember programming in c++ to teach a beginner class in programming logic. Subject that I haven’t seen in years. One struct was declared however when entering a string, the stream…
-
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
votes3
answers729
viewsPrint vector data in a struct
I want to do a birth-date registration system. The final question is: as I print the birthday: 1/12/1990, 12/2/1977, 13/09/1999 and 19/04/1987. Would be the examples of the printing of dates, but I…
-
4
votes2
answers14165
viewsDynamic allocation for struct
I need to dynamically allocate space for a structure, but I am not able and I do not know my error is at the time of the statement or allocation, follow the functions consistent with the statement.…
-
4
votes1
answer1023
viewsWhy is the size of a struct not the sum of the sizes of its variables?
For example, the following code: #include <stdio.h> struct exemplo{ char letra; int numero; float flutuante; }; int main() { printf("Tamanho do char: %u\n", sizeof(char)); printf("Tamanho do…
-
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
answers3911
viewsWhat is the difference between data types Enum, struct and Union in C?
I am reading the GNU’s C manual and I’m in the data types section and I notice a certain similarity between the types enum, struct, and union. Is the syntax the same, or is there something that…
-
4
votes2
answers1128
viewsfree(): invalid next size (fast) while trying to free up memory
I have this struct in a data structure and need to free up memory with it used: typedef struct { int capacityOfElements; //capacidade do vetor int numberOfElements; //número de elementos presentes…
-
4
votes2
answers98
viewsFaster way to add an item to a list, using a structure
Structure turma Public id_turma As Integer Public nome_turma As String End Structure Structure Disciplina Public id_disciplinas As Integer Public nome_disciplina As Integer End Structure Public…
-
4
votes1
answer2845
viewsWhat is the correct way to declare a struct in C?
Also how to rename data types with structures? I have doubt about it because of a Windows Manager that I use has the following code: typedef struct exem exem; struct exem { tiposdedado variavel; };…
-
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
answer97
viewsDoes it pay to store the value of a struct member in a local variable?
I see several programmers doing this. Instead of accessing a member of a struct directly, it copies the value to a local variable to the function and uses this variable. Is there performance gain in…
-
4
votes1
answer105
viewsVector reading in C is wrong
struct cadastro{ int codigo; char nome[200]; char cpf[11]; char rg[10]; char tel[12]; char end[100]; }cadastro;//struct do tipo cadastro. struct cadastro cd[max];//vetor da funcao cadastro de…
-
4
votes1
answer124
viewsHelp in struct C, unable to feed
Guys, good morning, I’m creating this simple code, just to read, and display, this vector information, like struct. Only that in executing this code, in the act of execution, I can not feed neither…
-
4
votes1
answer842
viewsWhat is and what is the sockaddr_in structure for?
Lately I’ve been wanting to program a network sockets in C++ but as the matters on the internet about it are a little limited coming to show only how to program the sockets without explaining in…
-
4
votes3
answers138
viewsIn structures (struct) is it necessary to use getters and setters or only in classes (class)?
It is necessary to use setters and getters in structures to maintain good practice or is needed only in classes?
-
4
votes2
answers366
viewsWhat is the typedef function in struct in C? Can I use struct without it?
I’m studying data structure in C, and every time my teacher uses the typedef us struct, but I don’t understand his function.
-
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
votes2
answers221
viewsHow to transform my code with static memory struct to C dynamics?
The exercise asks me to read information in a file, being them, Cpf, name, email and age of several people store in a struct, order in ascending order by age, if equal ages by Cpf, and print in…
-
4
votes1
answer73
viewsWhy is it that when I include my . h header, the . c implementation is not included as well?
I have three files, produtos.h, produtos.c and main.c. produtos.h is located in the folder "headers", produtos.c is located in "sources" and main.c is in the same folder as "headers" and "sources",…
-
4
votes2
answers250
viewsPrint struct data with read values from a text file in C
I’m trying to make a simple program to read data from a text file, store it in a struct, and print that data on the screen. The code I have is this:: #include <stdio.h> #define max 70 typedef…
-
3
votes1
answer2570
viewsWork with Struct and print problem, change Struct and delete Struct
I have a work at the college to do that consists of creating a structure of "Library Register"(cataloging code, name of the work, name of the author, publisher, donated works of each area, number of…
-
3
votes3
answers5915
viewsStruct and chained list
I created a person-like structure and I intend to use it in a chained list, but the following errors appear: 'No has no Member named 'data', 'No' has no Member named 'Prox' and unknow type name 'p'.…
-
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
votes2
answers121
viewsCan I return a struct by initiating it into a Return in ANSI C?
Good morning guys, I wonder if I can do something like this... typedef struct Result { int low, high, sum; } Result; Result teste(){ return {.low = 0, .high = 100, .sum = 150}; } I know this…