Thursday, December 21, 2017

What is a c structure

C structure

Every piece of the C programming language must be utilized in a particular order or manner. 
    This is what's called as the C programming language structure. To assist in controlling the program flow, the C programming language makes use of preprocessor directives. 
           The first function that is run in every C language program is the main function. The main function is a major requirement in every C language program. Without it, the program will not compile, much less run. Curly braces/ brackets are utilized to enclose the contents of the function. 
            What amounts to sentences in the C programming language area are what we call "Statements". Statements include but are not limited to C language functions, keywords, logical comparisons, math, and so on. Finally, we have the "comments." Comments are notes for other programmers, or yourself, who will be looking at the source code. 
                      Comments serve as general information or reminders and are not compiled as part of the source code by the compiler. Now since you now have a little background, let us put it to use by completing the dummy C language program that we wrote previously. 
        Return to the dummy.c program’s source code in the IDE’s editor. The main function is defined as an integer function. That means it returns an integer value to the operating system. 
     It is important that you know how the structure of C looks like at the bare minimum, before you can proceed to learn what its main building blocks are. 
            Once you know these basics, they will become your reference points as you learn more about the C language. 

The basic components of the C program:- 

1) The pre-processor commands 
2) The functions
3) The variables
4) The Statements as well as Expressions
5) The comments

For example :-

C structure example: “Hello, teacher!” What code could we use to print those words? 

(i) First of all, you would have your first program line as: #include <stdio.h>, being your pre-processor command. 

(ii) Your next would contain: int main(), being the program’s main function; and that is where the program begins to execute commands. 

(iii) The line that follows is: /*…*/. The compiler usually ignores it because it is where you are meant to add your comments if you so wish. You call such lines simply comments. Just for illustration’s sake, you could enter the comments: /* beginning to learn C */.

Compiling and executing c language are easy method:-

     Get your text editor open, and then type in the source code that you have 

       Next, save your file in the name of hello.c 

       The next action is opening a command prompt and moving to the specific directory where you have just saved your file.  

       Once there, type, gcc hello.c 

   Tap enter after typing that and you will have compiled your code 

     In case your process has been good and you have no errors within your code, you will be prompted to proceed to the line that follows. After this, you will see an executable file generated – a.out 

    You now need to type a.out to have your program executed. 

     Everything having gone well, you should be able to view your output 

– Hello teachers! – displayed on your screen.

    So basically showing on screen display on your screen 

$ gcc hello.c
Hello teachers!

Syntax of c structure on depended:-

          any process to work well, and for you to be able to issue the right commands, you should be able to identify every item for what it is. 
         That will avoid confusion and minimize errors. For that reason, in C programming, you need identifiers.

Their are defining types of c structure in computer language:-

1). The basic types of c structure.
2). The derived types of c structure.

1). The basic types of c structure:-

The basic data type in C is also referred to as the primary data type.
       It includes the arithmetic type, which is further categorized as integer, abbreviated as int; floating, usually represented as float; and character, usually represented by char and sometimes void. 
     When void is specified, it means that no value is being returned or reflected; and as for the integer, they represent variables.

The basic types of c structure name :-

Character           Integer           Float 
Void                     signed        unsigned 
Char                     Int              int
 float                  signed             char 
short                  int                 short 
int                      double         unsigned
 char                 long                  int 
long                  int                   long

Note that the integer data type stores whole numbers. In this regard, taking a 16-bit computer as an example, the signed int takes up two bytes;The unsigned int takes up two bytes; the signed short int takes up one byte; while the signed and unsigned long int take up space of four bytes each.When it comes to the float type of data, plain float takes up space of four bytes; the double takes up eight bytes; while the long double takes up ten bytes.

2). The derived type of c structure in c language:-

Under the derived type of data are functions; various data structures; and also pointers & variable.

a).  What is pointers apply c structure in derived 

 Well, a pointer happens to be a variable that has an address of another variable. It gives direction as to where that other variable is, helping to recall the contents of that other variable.
    You need to realize that pointers have nothing to do with object type. Take the following function, 

for example: 

 *malloc(size_t size)

Some character and example of pointers

int            *ip;          /*pointer to an integer*/ 
double    *dp;       /*pointer to a double*/ 
float         *fp;          /*pointer to a float*/ 
char         *ch;        /*pointer to a character*/

Note that whether you are entering pointer values that are integers or character; float or even double; what cuts across them all is the requirement that the value be one long number that is hexadecimal, and which is a representation of the memory address. Otherwise the pointers only differ in the specific constant or variable data type that each of them points to.

b).  Variable of derived in c structure :- 

Variables come up often in conversation, and they appear in many functions, not least in the C language. When it comes to the C programming language, a variable is simply a representative of storage area. 
It is the place where programs in C perform their manipulations. 
       Practically, you can use variables to store various data value. Variables are different from constants because as you execute your program in the C language, you can alter your variables, something you cannot do with constants. During programming, you may give your variables names that have ordinary meaning, like height or weight; age; average; and such.

Using the variable in c structure two major reason:- 

a) So that the compiler can recognize the name of the variable.

 b) So that it can be aptly categorized – given its appropriate data type. Read more 


Please comment and follow this site blog inbox