Home 0P3N Blog Let's "C" How this Goes: Programming Introduction to C
Ready to Start Your Career?
Create Free Account
jnox s profile image
By: jnox
December 12, 2016

Let's "C" How this Goes: Programming Introduction to C

By: jnox
December 12, 2016
jnox s profile image
By: jnox
December 12, 2016

code-1839406_1280

Hello there fellow Cybrarians! Let me start out by saying thank you! Thank you to all the people willing to take the time to help us learn about the IT world and willing to lend a helping hand to others, so thank you to everyone on Cybrary! ^_^ *Ghost hug* (you don’t feel it but it’s there)!

Ok, mushiness aside let’s get to the nitty gritty of this article. I have seen so many helpful articles come through here and appreciate them but I have not seen many on Programming, aside from a few such as Python or the Python course. Thank you for that wonderful course, by the way. I only wished there were some courses on other programming languages too, like C or C++.

So to help out in any way that I can, I will attempt to introduce C Programming in this article for those still learning or in need of a refresher. They say the best way to learn something is to learn it as if you are going to teach it. So let’s learn (or refresh) this together. Please keep in mind, I too am still trying to refresh and learn C Programming and do not claim to be an expert on this topic. In fact, if I mess up somewhere please let me know in the comments below, so that those learning will have the proper information. I’m not a professional writer but I will do my best. Well here it goes then…*gulp*…!

The language of C Programming has many uses, especially for those in the Cyber World, like hackers. Ok, don’t bite my head off, for those who don’t like the term ‘hackers’, for a newbie the simplest terms help stick to memory better so please just go with it. Any who, of course you have your ‘good guys/gals’ and bad guys/gals’ type of hackers, but we won’t get into that. The point is, C Programming, could be used for many purposes, some of which are; hacking an Operating System (e.g.-Windows), or Exploit Writing (e.g.-finding the weak spot or point in an application or system and ‘worming’ your way into it-not worm the virus, worm as in wiggling your way in), Reverse Engineering (e.g.-you know those games you “didn’t” pirate in order to play for free? That’s an example), and I suppose you could create a game but some prefer C++ (another programming language) for reasons that we won’t get into because it might take a while. Basically think of it like this, why do you choose to write with one type of pencil over another? Because the reasons can vary, ok so moving on.

Now you kind of know the ‘what it’s used for’ part of this. Now to know what you need to get started. You need a computer, obviously. I will assume you have one if you’re reading this article. Ok, now you need a compiler. What in the sugar cubes is that you ask? It’s basically a software that turns the program you coded in the C language, that you wrote, and turns it into an executable one so that both you and your computer understands it and can run it. You can either download a compiler or use an online compiler. Whew, ok, that was a mouth full. There are many compilers out there. Some that can run not only C but also some other programming languages too, like C++ or C# (C sharp, not C hashtag *keeps an eye on the hashtag reciter*). It would also help if you had either an article or course, or book to work from as you learn C Programming. There are many resources out there. I will link a few. *Cough Cough* I would link a Cybrary course but, ehem, I didn’t see one *looks at Cybrary experts* Perhaps one day then hmmm?  :)

Here are some helpful links to learn C Programming:

So what makes a C program? Well, the obvious and more smarty-butt answer would be code, but we want to take a slightly closer look. Almost everything has a beginning and an end, also true for most programming languages. C programming usually starts with, brace yourself techy terms incoming, a preprocessor, and a header. This is a ‘preprocessor’#include, and this is a ‘header’ stdio.h (stands for standard input/output header) but when coding you would write it as <stdio.h> , and yes you do write it with the ‘alligator mouths’ “<” and “>”. Why do we need these, though? Good question. Because you have to start somewhere, all joking aside. The preprocessor is basically the code that tells the compiler to do something, like a specific task before compiling the code written and they begin with a “#” (ok call it a hashtag, get it out of your system). There are other preprocessors, which are separate from compiling. And the header is basically a file that ends in “.h” (yes the dot is included); there’s more than one header type. So the header, like stdio.h, allows you access to use different functions that help you write your code, different functions for different tasks.  For example, the stdio.h header includes different functions, but one example is the printf function. I know, I just threw that in there, didn’t I? Calm down, we got this. I will get to that, let me finish this bit (not "bit" as in bit and byte J ). There are two types of header files; ones that you write and ones that the compiler writes, but don’t worry about what the compiler writes for now.

Now is that all the important parts? Nope(more techy talk incoming). The next important thing to remember, which follows the header is…*drum roll*…the ‘int main() { }’. That’s cute but what is it? First off, code is not cute. Secondly, it’s a function called main and has no parameters (nothing in the parenthesis). Yes, you can put something between the parenthesis, but for now, let’s not and just say we did. Putting nothing is something too right? Anyway, philosophy aside, the body of functions between the left and right braces ( { } ) is called a block. The ‘int’ part of the function tells the compiler that this function returns an integer value. So your block starts with the left brace‘ { ‘and you write all your code and ‘end’ block with the right brace ‘ } ‘ (but leave the parts out). And right before the right brace( } ), we end the compiled part of the code with a return 0; and that basically is the indicator that the program ended successfully. It’s used as an exit function, the exit status. So when it’s used at the end of ‘main’, the value 0 (zero) shows that the program worked fine. And since we have an ‘int’ in the beginning, we return an integer as well.

You know the beginning and the end, but what about the middle? Another good question, well remember that ‘printf’ function above? We are going to discuss that. But why so out of order you may ask? Well, I think it’s important to know how to start and stop something since the block part of your code could contain different functions depending on what type of program you’re trying to write (e.g.- a game, an application, etc). So the printf function basically tells the compiler: look I want you to display this output that’s between the quotes as it is, don’t add your own twist to it. (by the way, if you add a space, that is also included too, e.g.- printf(“Hello World  !”); would display the output as: Hello World  ! ). And you end that function with a semicolon ‘ ; ‘. So everything from the ‘p’ to the semicolon is called a statement, and as you get into more coding and write longer programs you will write many statements, and every statement must end with a semicolon, or else you will go nuts having many sleepless nights trying to find one simple little semicolon. But don’t pull your hair out just yet, if you make it a habit of ending a statement with the semicolon, you won’t have to worry about that being an error in your program. This is one statement: printf(“Hello World!”);

Now to end things, for now, with a complete program from beginning to end, which is the example you will most likely run into when first learning about how to code in C programming. Here you go, your first program…(*gets tearful*…”they grow up so fast”):

#include <stdio.h>

int main()

{

      printf(“Hello World!”);

return 0;

}

            See, not so scary, right? Don’t be afraid to ask questions if you have them. Remember, everyone and I mean everyone even the most badass coders, started out as a newbie or needed a refresher from time to time. A little saying I keep in mind when it comes to languages, be it for human or computer, is “Use it or lose it”. In other words, if you don’t practice, it’s easy to forget, which is what makes languages a fickle thing.  So I hope you enjoyed this short little lesson and hopefully it helped someone learn or get started in the wonderful world of programming; blood, sweat, tears, coffee, victories and all. Stay sane folks! ;)

Schedule Demo

Build your Cybersecurity or IT Career

Accelerate in your role, earn new certifications, and develop cutting-edge skills using the fastest growing catalog in the industry