Fire Tablet Alexa Display Black

Wednesday, May 9, 2012

Common Programming Concepts in C

Common Programming Concepts in C

Let's take a look at how to put some of the common programming concepts into practice in your C code. The following is a quick summary of these concepts:
Functions -- As stated earlier, a function is a block of code representing something the computer should do when the program runs. Some languages call these structures methods, though C programmers don't typically use that term. Your program may define several functions and call those functions from other functions. Later, we'll take a closer look at the structure of functions in C.
Variables -- When you run a program, sometimes you need the flexibility to run the program without knowing what the values are ahead of time. Like other programming languages, C allows you to use variables when you need that flexibility. Like variables in algebra, a variable in computer programming is a placeholder that stands for some value that you don't know or haven't found yet.
Data types -- In order to store data in memory while your program is running, and to know what operations you can perform on that data, a programming language like C defines certain data types it will recognize. Each data type in C has a certain size, measured in binary bits or bytes, and a certain set of rules about what its bits represent. Coming up, we'll see how important it is choose the right data type for the task when you're using C.
Operations -- In C, you can perform arithmetic operations (such as addition) on numbers and string operations (such as concatenation) on strings of characters. C also has built-in operations specifically designed for things you might want to do with your data. When we check out data types in C, we'll take a brief look at the operations, too.
Loops -- One of the most basic things a programmer will want to do is repeat an action some number of times based on certain conditions that come up while the program is running. A block of code designed to repeat based on given conditions is called a loop, and the C language provides for these common loop structures: while, do/while, for, continue/break and goto. C also includes the common if/then/else conditionals and switch/case statements.
Data structures -- When your program has a lot of data to handle, and you need to sort or search through that data, you'll probably use some sort of data structure. A data structure is a structured way of representing several pieces of data of the same data type. The most common data structure is an array, which is just an indexed list of a given size. C has libraries available to handle some common data structures, though you can always write functions and set up your own structures, too.
Preprocessor operations -- Sometimes you'll want to give the compiler some instructions on things to do with your code before compiling it into the executable. These operations include substituting constant values and including code from C libraries (which you saw in the sample code earlier).
C also requires programmers to handle some concepts which many programming languages have simplified or automated. These include pointers, memory management, and garbage collection. Later pages cover the important things to know about these concepts when programming in C.
This quick overview of concepts may seem overwhelming if you're not already a programmer. Before you move on to tackle a dense C programming guide, let's take a user-friendly look at the core concepts among those listed above, starting with functions.

No comments:

Post a Comment

am glad to view your comment!!