Most voted "c" questions
C is a general-purpose computer programming language used for operating systems, games, and other high-performance jobs and is clearly distinct from C++. It was developed in 1972 by Dennis Ritchie for use with the UNIX operating system.
Learn more…4,811 questions
Sort by count of
-
11
votes2
answers2240
viewsHow does C99 work in relation to C90 for declaring variables in the middle of the code?
At C90 and C89 we have to loop for must have its variable declared earlier at the beginning of the function scope, example: void main (void) { int i; for(i = 0; i < 10; i++) { /* Qualquer coisa…
-
11
votes2
answers1560
viewsHow to create an aquivo. h?
What good is a arquivo.h and what improvement it brings to the program in C++?
-
11
votes2
answers462
viewsHow to allocate dynamically when I don’t know how many positions I will use in C?
In a part of the code I need to transform an integer into binary and store it in a character array, however, I don’t know which integer I will receive to transform into binary, so I don’t know how…
-
11
votes2
answers3445
viewsHow to create a program in C and use Java/C#GUI?
I’m studying graphic interface in C, and I realized it’s very complex and tiring. So I wanted to know if there is how I create a program in C and use graphical interface of Java or C#. With use of…
-
11
votes1
answer143
viewsWhat does " " mean in the header of C++?
I was looking at the MFC header and I don’t know what the character " " means in this context: #define BEGIN_MESSAGE_MAP(theClass, baseClass) \ PTM_WARNING_DISABLE \
-
11
votes1
answer2858
viewsWhen should I use the "?" operator in C?
When I should use the ternary operator ? in C? #include <stdio.h> int main(void) { int valor, resultado; printf("\nValor: "); scanf("%d", &valor); resultado = valor < 10 ? 50 : 0;…
-
11
votes2
answers1506
viewsWhat is the difference between assigning and comparing string variables with function or with assignment and comparison operator?
I came across the following questions: What is the difference between expressions strcpy (s, t) e s = t ? What is the difference between expressions if (strcmp (s, t) < 0) e if (s < t) ? I…
-
11
votes1
answer338
viewsC libraries outside the ANSI standard
I am aware that, a C program in ANSI standard can be compiled both on Windows, both on Linux. But when it comes to using sockets? That’s not part of the pattern ANSI C? Because when I use sockets in…
-
11
votes2
answers3185
viewsBinary search in chained list
How can I perform a binary search on a simple chained list with head? Also if it is possible to do this, if there is some special method. In the EP I can not count beforehand the amount of elements…
-
11
votes4
answers1407
viewsHow to work with values that far exceed the long (64 bit) limit value
How is stored and performed operations with numbers that exceed the limit values of type long and double? How the four primary operations are done with these numbers (sum, subtraction,…
-
11
votes3
answers3123
viewsformat ľ%d' expects argument of type ěint', but argument 2 has type ěchar *' - What is it? How to tidy up?
Code: #include <stdio.h> int main(void) { char caractere, *caractere_ptr = &caractere; printf("Caractere: foi alocado %zu byte\n", sizeof(caractere)); printf("Endereço: %d",…
-
11
votes2
answers1385
viewsWhen to use "inline"?
Everybody says you don’t have to use inline functions since the compiler knows what to do better than the programmer. But if it has in the language it should serve for something. Is it useful in any…
-
11
votes2
answers12313
viewsHow to convert binary to decimal?
I had to make a huge equation to convert a binary number to decimal. What is the best way to make such a conversion? For example 0011 1011 0101 = 949 At the suggestion of Jorge B., I am putting my…
-
10
votes3
answers671
viewsA C program can tell which OS it is compiling?
I am developing a multi-platform C API and need to know if there is any way to know which OS is being compiled. For example, it could be a pre compilation directive #ifdef LINUX…
-
10
votes1
answer1271
viewsBecause the practice of "constant parameter" exists only in C
In C, there is the practice of applying the "const" modifier to function parameters when the function does not aim to change the parameter. As in this code: char process_string(const char *str);…
-
10
votes3
answers2325
viewsHow does the rotation of Bits in C work?
I would like to know how the bit rotation works, because the content I was able to find on the Internet does not explain for sure. Note: The structure is as follows: unsigned _rotl(unsigned…
-
10
votes3
answers25526
viewsHow to delete a character within a string?
In this code I read two strings and I withdraw from the first all the letters in common with the second string. But how to put a null character in place of this common letter in both strings? My…
-
10
votes1
answer269
viewsDifficulty in Syntax
I would like you to explain this function, I do not understand this syntax: double sum_arithmetic(double x0, double r, int n) { return n == 0 ? 0 : x0 + sum_arithmetic(x0 + r, r, n-1); }…
-
10
votes3
answers561
viewsNth value of a binary search tree
I’ve been trying to create a recursive function from the function that lists a binary tree in order. This function would return the term N-th, in order, from a binary search tree. Each node is in…
-
10
votes1
answer8664
viewsSocket between 2 clients and 1 C server
How to receive two connections? The system consists of 2 clients and 1 server, the server must receive the connections and initiate a sequential conversation with the clients. I was able to…
-
10
votes1
answer400
viewsIs it good to use global variables for greater readability in the code?
I am implementing an exercise of the Deitel book, How to Program C, 6th edition, the Logo problem in chapter 6. It was an interesting question with legal logical problems etc. The only question of…
-
10
votes3
answers42472
viewsError Segmentation fault (core dumped)
I’m getting the following error message in my code: Segmentation fault (core dumped) Another thing is, when I performed the same function operation preenche in the main, using ficha.name in place of…
-
10
votes1
answer882
viewscomparison of floats
This program allows you to check which of the three floats is the largest, only it is ignoring the decimal places. For example if I put the values 1.4, 1.6 and 1.5, the program tells me that the…
casked 9 years, 5 months ago kingwarrior05 617 -
10
votes2
answers57301
viewsHow to limit decimal places?
I have a question, it has to limit the number of decimal places in C++? float x = 2.958; Instead of rounding up or down using floorf, roundf, can only take the two numbers after the comma? that…
-
10
votes3
answers2257
viewsWhich loop is faster in C: while or for?
Being a bond while and a for that run the same number of times, which is faster? Example: while: int i = 0; int max = 10; while(i<max){ funcao(); i++; } for: int i; int max = 10; for(i=0;…
-
10
votes1
answer3215
viewsPerform music in the program in C
I need to run a song while running a program in C. In Windows we can do so - if the file is in the same program directory: #include<stdio.h> #include<stdlib.h> int main (){ system("start…
-
10
votes2
answers925
viewsHow do C’s hands work?
first What is the difference between declaring: char* s and char *s? 2nd It is always necessary to use the function malloc when declaring a inter? Example: char* s = malloc(sizeof(char)); //ou…
-
10
votes2
answers3616
viewsWhat is the difference between a file . c and . cpp?
C and C++ are two different languages, however C++ is a "superset" or superconpin of the C language. So what is the difference between a file with the .c and .cpp?…
-
10
votes2
answers559
viewsBinary Search Tree vs Sorted List
Consider an unbalanced binary search tree and an ordered vector list. Which of the two structures is best suited to perform a search for any element.
casked 8 years, 1 month ago Andrey França 2,313 -
10
votes3
answers302
viewsWhat is the cost of calling many functions?
Recently, faced with a discussion about Clean Code and programming best practices, a co-worker commented that in his previous job he had a lot of resistance on the part of the other programmers to…
-
10
votes1
answer896
viewsWhat is MUSL? What are the pros of someone carrying it on my laptop?
I’m interested in the pros that this can bring to my laptop.
-
10
votes2
answers930
viewsPrototype functions in C/C++
What kinds of functions are these? What can these prototypes do? /*1*/int func ( int (*x)(int,int) ) /*2*/int func ( int x(int,int) ) /*3*/int func1 ( int(fn)() ) /*4*/int func2 ( int(*fn)() ) Is…
-
10
votes1
answer766
viewsTo learn C++ is it necessary to learn C?
In case I want to learn about C++ I need to learn C before or they are different?
-
10
votes3
answers685
viewsPrevent the CMD command interpreter from using the operators passed via parameter/argument?
There is a way to prevent operators present in past arguments, via command line, from being used/interpreted by the interpreter CMD in C, C++ or C#? I want to make use of characters present in the…
-
10
votes2
answers158
viewsWhat happens to memory when "realloc()" reallocates a memory block to a value less than the original?
Suppose I allot a dynamic matrix of 10 ints and assign some values values to it, then I use the function realloc() to reallocate the matrix to 3 ints, what happens to the other 7 ints, they will be…
-
9
votes2
answers4823
viewsHow to access a specific RAM location by address?
I’m starting to study C/C++ pointers and it was something that caught my attention by the robustness and the range of possibilities. However, I can only access memory positions by assigning to my…
-
9
votes4
answers459
viewsWhat happens when I convert int to char?
A whole has 4 bytes, whereas a char has only 1 byte. When I make that definition: int a = 1000; // 1111101000 char b = (char) a; I believe it will take only 1 byte of data, but what I want to know…
-
9
votes3
answers4910
viewsSplit result equals zero in decimals
In division 1 by 3, my program is printing the following: number e' of 0.00 What is the error in the code? #include <stdio.h> int main(){ float numero; numero = 1/3; printf("o valor do numero…
-
9
votes3
answers1348
viewsProblems with "or" in C++
I need to make an algorithm that gets 3 different numbers, and if it gets repeated numbers, it gives an error message. My program is all working properly, but when I put such a line to warn of the…
-
9
votes1
answer2493
viewsWhat are logical operators and how do bit-to-bit operations work in the C language?
What are logical operators NOT, AND, OR, XOR, in language C? Nor did I understand these operators: ~, &, |, ^, >>, << and the result in bits. I have the following example of code:…
-
9
votes1
answer1625
viewsHow to include a C function in Python?
I want to use a function made in C. Example: I have a function int swap(){ printf("lista"); } And I want to call you by Python...…
-
9
votes4
answers12732
viewsMultiple return in C/C++
Is it possible to return multiple values? For example: umafuncao() { int x = 1, y = 2; return x,y; } void main() { int a, b; a, b = umafuncao(); } I’m asking this question because I built a code…
-
9
votes3
answers4376
viewsWhat is the purpose of the return of the main function and the importance of this function?
I would like to know the importance of the function main and what is the purpose of her return which is a whole? See a minimum example of function implementation main: int main() {…
-
9
votes2
answers2598
viewsCan this asterisk pyramid code be further simplified?
I have a simple exercise where I need to do an asterisk pyramide using repeating structure. The pyramid has 17 columns and 9 rows. My program displays it correctly, It is possible to reduce some…
casked 8 years, 7 months ago Marco Oliveira 125 -
9
votes1
answer4004
viewsHow to limit reading decimals (scanf) of a double variable?
The exercise asks the readings of the variables double are limited to only one decimal place each of them. I tried to put "%.1lf" in the scanf, as we used in the printf, but it didn’t work. How…
-
9
votes3
answers4855
viewsUsefulness of #pragma
Several C/C++ codes have the word pragma. Depending on the way it is implemented it has a different function. #pragma Once #pragma pack() #pragma comment(xx, "") For what purpose the pragma was…
-
9
votes2
answers235
viewsWhat does the _t suffix mean and when to use it?
I see in many codes some variables with the suffix _t. There are a lot of examples in the standard C library like size_t, int32_t, mbstate_t. What is the use, and when to use this suffix?…
-
9
votes3
answers11758
viewsWhen to use const and when to use #define
Since the two do the same function there is some difference between one and the other? I’ll take the code from this site as an example C - Constants & Literals The #define Preprocessor #include…
-
9
votes1
answer1239
viewsWhat’s the difference between #include <filename> and #include "filename"?
Why do we use #include <filename> and #include "filename" When to use each?
-
9
votes1
answer855
views