Questions tagged as 'c'

2
answers

char [] or * char malloc?

What difference in C between char text[10] or char *char = (char *)malloc(10*sizeof(char)); What advantage of using malloc on a pointer?     
asked by 21.07.2016 / 20:10
2
answers

How to allocate dynamically when I do not 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 vector of characters, however, I do not know which integer I'm going to get to binary, so I do not know how many positions my vector will have %. How to handle...
asked by 31.08.2015 / 02:56
1
answer

Play music in C program

I need to run a song while running a program in C. In Windows we can do this - if the file is in the same program directory: #include<stdio.h> #include<stdlib.h> int main (){ system("start music.mp3"); return 0; } The file...
asked by 14.12.2015 / 00:04
2
answers

Why assign NULL on a pointer after a free?

I see in many codes assigning NULL to a pointer just after a free , type: free(p); p = NULL; What would be the advantage of this?     
asked by 05.06.2018 / 15:10
2
answers

How do I access a specific RAM location by address?

I'm starting to study pointers in C / C ++ and it was something that drew my attention to the robustness and range of possibilities. However, I can only access memory locations by assigning my pointer an address of an already allocated variable,...
asked by 13.03.2014 / 18:07
3
answers

Which loop is faster in C: while or for?

Being a loop while and a for that rotate 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; i<...
asked by 10.12.2015 / 19:00
3
answers

Range of random numbers in C

In a certain program, I need to generate a random value greater than 1000 (with a limit set by me for up to 5000 (maybe still a very high value)). This unique code refers to a type of registration to be performed. After solving some doubts of...
asked by 05.11.2014 / 01:09
4
answers

Multiple 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 using this structure for a...
asked by 03.11.2015 / 14:25
3
answers

What is the cost of calling many functions?

Recently, in the face of a discussion on Clean Code and best programming practices, a co-worker commented that in his previous job there was a lot of resistance from other programmers to begin dividing code and make it more readable. The mai...
asked by 15.02.2017 / 20:29
1
answer

How to limit the decimal places of the scanf of a double variable?

The exercise asks that the readings of double variables be limited to only one decimal place each. I tried to put "%.1lf" in scanf , just like we used in printf , but it did not work. How could I solve this? int ma...
asked by 12.08.2016 / 05:55