Difference between macros and constants in C

  Рет қаралды 12,565

CodeVault

CodeVault

Күн бұрын

Пікірлер: 23
@kutalpdilber8815
@kutalpdilber8815 3 жыл бұрын
an elaborative and explanatory video, feeling lucky that i have discovered this channel
@abelashenafi6291
@abelashenafi6291 Жыл бұрын
I'm really liking your videos. You just became my go to person when I want to learn about some advanced C++ topics. I did my own experiment after watching this video. If someone really wants to truly understand the difference between a constant and a Macros in C or C++; one could simply try to print out the memory location of both, and as this video vividly explained, marcos are just preprocessor directive that replace your macros in your program, which are NOT stored in memory. Doing this experiment helped in finally understanding the difference between marcros and const variables. I strongly suggest everyone watching this video to do the same :).
@wiktorwektor123
@wiktorwektor123 3 жыл бұрын
C/C++ compilers are working ALWAYS in 4 phases: 1) Preprocessor (everything starting from #) 2) Compiler 3) Assembler 4) Linker
@arberhoxha8523
@arberhoxha8523 2 жыл бұрын
Wasn't the assembler optional?
@emjaqua
@emjaqua 2 жыл бұрын
Awesome videos. Really impressed with the direct, focused information.
@ifeanyizionchidiebere6369
@ifeanyizionchidiebere6369 Жыл бұрын
i am now hooked up to your videos, you are the best teacher.😊🙃
@Принуждениекмиру-ь2ц
@Принуждениекмиру-ь2ц 2 жыл бұрын
Man, you're the best in KZbin. Thanks a lot. 👍❤️
@Ejeby
@Ejeby 3 жыл бұрын
9:15 why would one prefer to use constants instead of macros (aka symbolic constants?) if the output of preprocessing macros offers better debugging?
@CodeVault
@CodeVault 3 жыл бұрын
I'm not sure what you mean by this: "the output of preprocessing macros offers better debugging" The main reason I said that is because constants have types which can be checked at compile time, while, macros don't. With macros, of course you will get a compile time error most of the time but it could be confusing. I guess, with enough experience it doesn't really matter
@Ejeby
@Ejeby 3 жыл бұрын
9:45 how does one find the computational cost of variable dereferencing? And compare that to cost of macro/preprocessing?
@Ejeby
@Ejeby 3 жыл бұрын
10:15 I understand that there’s usually no difference if you’re using a “modern compiler”
@CodeVault
@CodeVault 3 жыл бұрын
Hmm... for the most part the difference would be negligeble (but remains to be tested). I say that because, constants do actually get replaced by hard-coded values at compile time (similar as to macros) since compilers now understand that there is little benefit to allocating memory for those constants at runtime so they are just stored as literals
@mikeyo5154
@mikeyo5154 2 жыл бұрын
Great discussion
@PeacelandMusic
@PeacelandMusic 2 жыл бұрын
Is it possible to use a macro to define an element of an array? I tried it with int const sameVar and it didn't work (error on that line). I want to be able to change elements of my array using a variable that is easy to access. The other reason is that I have 3 columns in the array and 2 of them need to be the same value, but they are not in succession. They skip: myArray[3] { (x=zVar ), y , zVar }. Can this be done? Ultimately hoping to do this as a multidimensional array in C. Thank you! Peace
@CodeVault
@CodeVault 2 жыл бұрын
Hmm... I'm not entirely sure what you're asking. Can you send me the code so I can better understand?
@chriso.wilkie7915
@chriso.wilkie7915 4 жыл бұрын
Oh man, I wish I could hire you as a tutor for few hours. I have so much to ask you
@CodeVault
@CodeVault 4 жыл бұрын
Just send me a private message on discord.code-vault.net and we can figure out the details!
@Ejeby
@Ejeby 3 жыл бұрын
9:55 constant const int
@abdoroma6928
@abdoroma6928 Жыл бұрын
So cool
@TalhaAbid-l2b
@TalhaAbid-l2b 8 ай бұрын
The best
@zaabimahdi
@zaabimahdi 4 жыл бұрын
Hallo ! thank you again for the the high informative videos ! Please , i have a question that is depressing me now for 2 weeks ... It's about the Macro EOF (End Of File) ... "i'am using getline" I understand how to use it in an infinte while loop ... But please could you explain me how getline detect the end of file ? i know that Getline return the number of bytes that was read in success , and return -1 on failure or EOF ... But how Getline detect the end of file so it's return -1 ? i was searching on the internet for hours , the only answer that i found : ctrl+d to simulate the EOF on linux ... which is not the case if you want to develop a program that keeps reading the input line and detect the end of FILE by itself and not the USER ! i would be very happy if you could answer me ! Thank you .
@CodeVault
@CodeVault 4 жыл бұрын
I'll look into it
@sadeeshkumarmsd
@sadeeshkumarmsd 2 жыл бұрын
Thanks sir
Difference between memmove and memcpy
9:15
CodeVault
Рет қаралды 27 М.
How to Write Function-Like Preprocessor Macros (C example)
13:59
Jacob Sorber
Рет қаралды 44 М.
🎈🎈🎈😲 #tiktok #shorts
0:28
Byungari 병아리언니
Рет қаралды 4,5 МЛН
요즘유행 찍는법
0:34
오마이비키 OMV
Рет қаралды 12 МЛН
What are variadic functions (va_list) in C?
13:49
CodeVault
Рет қаралды 26 М.
What are double pointers in C?
14:43
CodeVault
Рет қаралды 46 М.
Generic data types in C
14:58
CodeVault
Рет қаралды 22 М.
Defining Constants. Should I use CONST or #DEFINE?
7:59
Jacob Sorber
Рет қаралды 59 М.
"Clean" Code, Horrible Performance
22:41
Molly Rocket
Рет қаралды 944 М.
array vs &array Pointers Difference Explained | C Programming Tutorial
17:38
A const int is not a constant.
9:16
Jacob Sorber
Рет қаралды 70 М.
Master Pointers in C:  10X Your C Coding!
14:12
Dave's Garage
Рет қаралды 343 М.
Intro to recursive functions in C
17:38
CodeVault
Рет қаралды 13 М.