To conserve space. Instead of typing: int age; int currentYear; int birthYear; I just type: int age, currentYear, birthYear; I've learnt so much after just 1hr+, man! You're absolutely brilliant!
That won't conserve space. It will only take up one line instead of three in your source code, but once the computer compiles your code, it will take up the same amount of space no matter which way you do it.
A variables is a way for you to store values into computer memory. When you create a variable, you are actually telling the computer you wish to use some of it's memory to store some numbers in (even characters, as each character has a numerical value that gets stored). But, you need to tell the computer how much memory you wish to use, so you set the type, like "int", tells the computer you wish to store an integer, not a floating point (it has no fractional values). All ints on 32bit computers are four bytes, so the computer sets aside four bytes of memory to store your number in. You then give that int a label for you to access it. You could literally access the numerical memory address it uses, but that would be harder to remember than an actual word as a label. You then tell it what value you wish to store into that memory location. When you use it later on, the computer will basically look for where that label is in memory, look at that location in RAM, pull the value out and display it on screen (or if it's a character, it pulls the number, then looks up on a table what the letter is that number represents then displays that character). You can actually display the numerical value of a character if you wish. It is IMPORTANT to understand that ALL variables are stored in memory and that the variable name references a memory address where your value is stored. This will become important later on when you learn about something called pointers, which basically point to an address in memory.
Bucky your the man bro. I cannot tell how much I appreciate your tutorials . I would have paid my last and kept my priceless learning treasure far away from the unappreciatives. Thanks again my brother.
+Peterolen %d stands for decimal. You can use %i in C and it'll still print an integer, but %d is more specific because %i can take in a hexadecimal, or octal base integer.
Hey man thanks for the vids. Im in programming classes and the book reads like stereo instructions. And every video you have covers all the chapters in the book so thanks for the great vids. You break everything down and make it so much more understandable. Thx again
How can someone dislike this ????? Such amazing tutorials. Love this so much. I have learnt so much in a few days. You sir are an incredible citizen. God bless your soul.
Really good video's dude. Much appreciated. I'm taking an algorithm and design class and we are using C to write our first program. Scary stuff but this really helps!
If you wanna learn guys u need to follow these steps by steps but try to do some exercise otherwise u won't get it. I love the way u are taking the time because I see some videos where they go really fast. Sometimes I forget semicolons but inmediately I got an error under and I correct it. Really nice program.
Through this video, I learnt how to make a basic calculator. Here is the code: #include int main() { int num1; int num2; int sum; int subtract; int multiply; int division; printf("Enter the num1"); scanf("%d", &num1 ); printf("Enter the num2"); scanf("%d", &num2); sum = num1 + num2; printf("the sum of these numbers is %d ", sum); subtract = num1 - num2; printf("the difference of these numbers is %d ", subtract); multiply = num1 * num2; printf("the product of these numbers is %d ", multiply); division = num1 / num2; printf("the division of these numbers is %d ", division); return 0; }
Your tutorials till now have helped me out as i am starting from scratch in here and i started with your videos a week ago and it's going pretty well, but i have some questions i need an answer for, because i keep practicing and what i figured out that when i put the variables age, current year and birth year while not deleting the first line which is int age alone, it gives me an error till i change age into something else like ege for example then it runs very good, i know how stupid it is but actually i will do anything to learn, thanks in advance :)
Thanks for video. Question: int name; name = "Mrs X"; why string has to be declared as int to get it printed? i tried str name; < but it's incorect and we use int to declare string?
Age calculator where the user gets to input his current year and birthyear, #include #include int main() { int age; int currentYear; int birthYear; printf("Enter your birthyear"); scanf("%d",&birthYear); printf("Enter your currentyear"); scanf("%d",¤tYear); age = currentYear - birthYear; printf("you are %d years old", age); return 0; }
To conserve More space. Instead of typing: int age; int currentYear' int birthYear; currentYear = 2015; birthYear = 1987; age = currentYear - birthYear; i just type: int age, currentyear = 2015, birthyear = 1987; age = currentyear - birthyear; _ C = bucky + thenewboston; Thanks C.! :D
nice. i was going through the age code with you on my code block try to figure out my age and i noticed you didn't explain why the Year was capitalized. so i tried it with lowercase on the int and the program failed. i guess capital letters with no spaces is the way the computer can differentiate one word from another when not in strings? int currentYear vs printf("current year is blah")
This is done to save space. Imagine you are going on a trip. It would be silly to pack everything you own for the trip, right. You only pack the things you need. C does the same thing, each library you call packs the things that you need for your program. This is done to save memory and speed up a program. When you use C for something that isn't a computer, say a microcontroller, you would run out of space very fast and it would slow down your program. Your compiler might optimize these unused pieces of code out but you can not be sure of that. You can search C libraries online to find what functions are located in each library.
like the ones before me told you, it are librarys which other people already programmed for your usage. so you don't have to teach your program what the mathematical operations "+, -, x, /" means and how they work. It meaks the life much easier and saves a lot of time and storage.
Does anyone knows how to activate the "red box"error symbol afterr compiling code. Mine doesnt have the red box which s inconvenient since i have to go to logs to find error line number. Thx
Is there a way to work out age with the months as well as years? I may be born in 1987 but if it's only July and I'm born in October then I'm not 29 yet.
maybe you can keep month variable equal to 10 (october) and write an if statement (later tutorials maybe) to see if the birth month is more than the current. If it is true, then year - current else year - current - 1
With the function printf both works equal... but when you use the function scanf (for get input information) they work different, the i in %i stands for integer, and the d in %d stands for decimal... PD: Sorry for my english, but I am Argentinian
int main() { char you[4] = "Alex"; printf("My name is %s ", you ); } It prints "My name is AlexD... Even if u change the you, It still prints with "D". Why?
Now obviously that program wouldn't actually work to find your age all the time, as that also depends on the month, if you were born in December but it's only August, that program would print out 1 year older than you are, because it doesn't factor in the month/days/etc.
int lgelength, armlength, value, finalresult; leglength=2.5; armlength=3.5; value=leglength/0.2; final result = armlength+value; printf(" height of a person is %d", finalresult); return 0; for the above code the output should be 13. But i am getting 12. if any one know why is this happening please reply to this comment
Bucky hey I was wondering why doesn't code like this out put 20 in the second printf line.Please get around to me or anyone else. #include #include int main () { int age ; age=20 ; printf("This is Joseph's age %d ",age); printf("Joseph is",20,"years old"); return 0; }
Because you can't just slap a number like that in the middle! You use the comma only in conjuction with a variable and a conversion character. printf("Joseph is %d years old", age); You also dont really need two newlines but whatever