No video

Static Keyword in C Part 2/2

  Рет қаралды 20,933

HackerCS

HackerCS

11 жыл бұрын

Master converting between hex, binary and decimal in your head with this game: play.google.co...
Follow more CS videos @ hackercs.com

Пікірлер: 21
@proggenius2024
@proggenius2024 5 ай бұрын
thanks, please do more. We need more advanced c series
@benjahnz
@benjahnz 5 жыл бұрын
Great concise tutorial with clear examples. Nice work buddy!
@MakeItStik
@MakeItStik 4 жыл бұрын
Great explanation. Thank you so much. Please continue making such videos.
@bhavyakukkar
@bhavyakukkar 3 жыл бұрын
why was the 'extern' keyword not required while declaring the print_num( ) function in the caller file?
@esijal
@esijal 2 жыл бұрын
Very nice 👍
@santosharyan884
@santosharyan884 9 жыл бұрын
thanks for ur great teaching,is this program give same result in turbo c,i dont think so,where r your other video s i want explaination abt global variables,
@shubhac4970
@shubhac4970 4 жыл бұрын
If there is a global static var x in file1.c and file2.c. How do we map the var in the .bss segment to that particular file?
@ulysses_grant
@ulysses_grant 6 жыл бұрын
Amazing job man. Thanks so much.
@aadil6081
@aadil6081 8 жыл бұрын
great tutorial on "static" keyword,
@DragonSolidSnakeNY
@DragonSolidSnakeNY 11 жыл бұрын
when would you need to use static on a function level to limit the scope? I've used static as a life extender for a variable before but never used it on a function in C. I used static in java on a function level but that just affects how you call it, I think.Also thanks so much for your videos you got me through my C++ and data structures course!.
@ricardoperez7580
@ricardoperez7580 8 жыл бұрын
quite clear tutorial, thanks so much
@iDROIDchannel
@iDROIDchannel 4 жыл бұрын
I know that a lot of time gone... But why don't you marked the print_num() prototype as 'extern' in caller.c?
@bhavyakukkar
@bhavyakukkar 3 жыл бұрын
i have the same doubt
@rustycherkas8229
@rustycherkas8229 2 жыл бұрын
Short answer: All vars declared (and thereby defined) outside funcs() are "globally visible" by default. 'Extern' was needed with 'int x;' (in this poor 'lesson') to DECLARE to the compiler that the LINKER will (should) find 'x' DEFINED (space allocated) somewhere in a related OBJ... Function prototypes are not function DECLARATIONS; they are simply 'promises' for the compiler to check parameters and return types. One could prototype a function "void foobar( int, float*, (char*)(int, int), int**);" and then never get around to writing the actual code for it... Just don't try to call it! Putting 'extern int x;' or the function prototype into caller.c is HORRIBLE practice. The compiler will not be able to confirm the func's parameters and return type (its "function signature") are correct. Likewise, 'x' may be declared an 'char *' in main.c, and 'float *' in caller.c... Good luck!! The compiler is helpless. This is why #include "foobar.h"; (header files) must be used to declare common (global) variables and functions. It is also why some version of "makefile" should be used for the compiler to know what OBJs and EXEs are stale after one or more source files has been altered. CAUTION: Do not declare static vars or static funcs in a header file (unless you know what you're doing). Each OBJ would otherwise receive its own private instance of declared variables... A better (minimal) example: FOO.h #include extern int x; // prototype declaring there exists a variable named 'x' and that its type is 'int' void print_num(void); // prototype declaring there (may) exist a function (taking no params and returning nothing) void caller(void); // another function prototype DATASPACE.c #include "foo.h" // For compiler to 'see' and check that 'x' is a well-known integer data type... int x = 0; // definition of variable. (space allocated) CALLER.c #include "foo.h" // For compiler to 'see' there exists an 'x' and a 'print_num()' to link void caller(void) { print_num(); x = x + 1; } MAIN.c #include "foo.h" // For compiler to 'see' there exists an 'x' and what 'caller()' looks like... void print_num(void) { printf("%d ", x ); } int main(void) { caller(); // Will print "0" caller(); // Will print "1" }
@shahriarshahabuddin5908
@shahriarshahabuddin5908 7 жыл бұрын
Very nice tutorial.
@battleroundscool
@battleroundscool 9 жыл бұрын
excellent
@MrShubhambindal
@MrShubhambindal 10 жыл бұрын
Very helpful. Can u tell me the software u r using for compilation
@tb6618
@tb6618 9 жыл бұрын
he is using gcc... Its in code blocks for windows and in Linux . The Os he is using for this is Linux.
@thangbanben5683
@thangbanben5683 7 жыл бұрын
Tatrasiel R i have been using C to program microcontrollers. I didn't know we can compile code right from pc using gcc. Looks so convenient. Thanks :)
How to Return an Array from a Function in C Part 1/2
16:10
HackerCS
Рет қаралды 65 М.
Reading and Writing C Type Declarations Part 1/2
11:49
HackerCS
Рет қаралды 11 М.
天使救了路飞!#天使#小丑#路飞#家庭
00:35
家庭搞笑日记
Рет қаралды 59 МЛН
OMG what happened??😳 filaretiki family✨ #social
01:00
Filaretiki
Рет қаралды 10 МЛН
Logo Matching Challenge with Alfredo Larin Family! 👍
00:36
BigSchool
Рет қаралды 8 МЛН
The importance of Volatile keyword-Part 1
9:54
Fastbit Embedded Brain Academy
Рет қаралды 33 М.
Static Keyword in C Part 1/2
5:12
HackerCS
Рет қаралды 75 М.
Understanding Ownership in Rust
25:31
Let's Get Rusty
Рет қаралды 250 М.
Syntax of Structs and Unions in C
13:09
HackerCS
Рет қаралды 10 М.
How to Return an Array from a Function in C Part 2/2
14:33
HackerCS
Рет қаралды 20 М.
Reading and Writing C Type Declarations Part 2/2
8:52
HackerCS
Рет қаралды 7 М.
What is a mutex in C? (pthread_mutex)
9:18
CodeVault
Рет қаралды 160 М.
Reading and Writing Files in C, two ways (fopen vs. open)
7:07
Jacob Sorber
Рет қаралды 100 М.
C pointers explained👉
8:04
Bro Code
Рет қаралды 157 М.
天使救了路飞!#天使#小丑#路飞#家庭
00:35
家庭搞笑日记
Рет қаралды 59 МЛН