C Programming Tutorial 15 – Using Functions in C

We’ve had a small number of videos so far covering C in general. The goal of the previous videos was largely to introduce you to a number of the beginning features of C. As we move on, we’ll probably be going into a bit more detail.

One thing I will discuss in a lot of detail later on is called functions. I thought I would give a video to introduce them to you in some detail so as we use them you are not totally confused.

A function is essentially a section of code that can be called numerous times. For example, let’s say you are outputting three things to the console, and you are going to do that every minute or so to see how certain data changes over time. So let’s say we are outputting the value of x, y, and also the current time.

Well, we the code we would use would look something like printf(…); printf(…); printf(…);. Then, when we need to output the data again, we can call the same three statements again.

This can work, but it is not the best. For example, let’s say you output this data a few times, but now you changed your mind and would like to update the format that is being outputted. Now you have to go back and change it in every location. This is very error prone.

Instead, we could write what is known as a function, such as printData(), and we would define all of the code to be inside of that function. Later on we will get into how to make functions, but for now let’s just say we made that function and everything is working. Now, everywhere that used to have the repetitive code can be replaced with a call to that function.

If you want to update the format now, all you have to do is change it in one place, reducing errors and making coding easier.

This is obviously a very simple example, but functions can be used to do a lot of cool complex things. You will see functions every day of your life when programming. In fact, printf() is a function itself. Somewhere there is code that knows how to output stuff to the console, so all you have to do is give some data to the printf() function.

So, this video is more about focusing on using functions rather than creating them, and printf() is a common function that you are going to use. It allows you to give data to be printed. When you give a function some data data, the computer sciency term is called passing data. Specifically, you can say you are passing data as an argument.

So, let’s say we have something like this:

printf(“%d\n, 55);

We are passing two arguments to the printf() function.

Don’t feel like you have to understand everything about functions. Usually functions aren’t really focused on until you have a good understanding of the basics of C programming. Later on we’ll talk about creating function, taking data through parameters, and returning data. But this Is truly good for right now.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Support me! http://www.patreon.com/calebcurry

Subscribe to my newsletter: http://eepurl.com/-8qtH

Donate!: http://bit.ly/DonateCTVM2.

~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~

More content: http://CalebCurry.com
Facebook: http://www.facebook.com/CalebTheVideoMaker
Google+: https://plus.google.com/+CalebTheVideoMaker2
Twitter: http://twitter.com/calebCurry

Amazing Web Hosting – https://www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)

Comments

Baburam Chaudhary says:

It would be better if you add more topics like: pointer, structure and union, file handling and more tutorials on function in C language.

Write a comment

*

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.


Do you like our videos?
Do you want to see more like that?

Please click below to support us on Facebook!

Send this to a friend

▷ Other ReviewsVehicles▷ Show Cars▷ Motorbikes▷ Scooters▷ Bicycles▷ Rims & Tires▷ Luxury BoatsFashion▷ Sunglasses▷ Luxury Watches▷ Luxury Purses▷ Jeans Wear▷ High Heels▷ Kinis Swimwear▷ Perfumes▷ Jewellery▷ Cosmetics▷ Shaving Helpers▷ Fashion HatsFooding▷ Chef Club▷ Fooding Helpers▷ Coktails & LiquorsSports▷ Sport Shoes▷ Fitness & Detox▷ Golf Gear▷ Racquets▷ Hiking & Trek Gear▷ Diving Equipment▷ Ski Gear▷ Snowboards▷ Surf Boards▷ Rollers & SkatesEntertainment▷ DIY Guides▷ Zik Instruments▷ Published Books▷ Music Albums▷ Cine Movies▷ Trading Helpers▷ Make Money▷ Fishing Equipment▷ Paintball Supplies▷ Trading Card Games▷ Telescopes▷ Knives▷ VapesHigh Tech▷ Flat Screens▷ Tech Devices▷ Camera Lenses▷ Audio HiFi▷ Printers▷ USB Devices▷ PC Hardware▷ Network Gear▷ Cloud Servers▷ Software Helpers▷ Programmer Helpers▷ Mobile Apps▷ Hearing AidsHome▷ Home Furniture▷ Home Appliances▷ Tools Workshop▷ Beddings▷ Floor Layings▷ Barbecues▷ Aquarium Gear▷ Safe Boxes▷ Office Supplies▷ Security Locks▷ Cleaning ProductsKids▷ Baby Strollers▷ Child Car Seats▷ Remote ControlledTravel▷ Luggages & Bags▷ Airlines Seats▷ Hotel Rooms▷ Fun Trips▷ Cruise Ships▷ Mexico Tours