I'm lost in the world of C Language

I'm lost in the world of C Language

ยท

3 min read

In my last blog post, I mentioned that I was halfway through the second month of the ALX software engineering course. This month is Month 1, while the first month was Month 0 as a sort of "welcome month". Don't let that fool you though it was more overwhelming than welcoming. I might have had it easier for me anyway since I made it through Month 0 already in my first attempt on the course. It has been a week of Preprocessing, structures and typedef. I would try to do a whimsical recap of what I have been able to understand so far.

Processing C language

Processing C language occurs in 4 main steps; Preprocessing, here directives(beginning with #) to introduce header files and macros. Actions and conditions to be taken before compilation are taken care of here.#include <stdio.h> stdio.h is a header file containing macros (reusable code snippets that have simple or complex use ) for input and output like print() and scanf(). As the name implies Preprocess. Compilation converts the preprocessed code to assembly language. Assembling is where the assembly language is converted to machine language that the computer understands and can execute. The machine code needs to be linked to some libraries to be an executable file. this process is known as Linking. The final stage is Loading and executing, the code is loaded int to memory and executed in the Processing unit.

Structures and Typedef

The type of Data encountered have different types. int, char, float... So the data type has to be specified. For example, you are working with age which is an integer you have int age;. But now let's say you want to fill in or request the details of a student, the name, age and gender. You have 2 character data types and 1 integer data type involved. Grouping these different types this is where Structures come in.

So struct groups them under student. typedef gives the struct a name.

struct Student {
    char name[50];
    int age;
    char Gender[20];
};
//Now when we want to declare variables 
int main() {
    struct Student student2;

 //This line has to be written every time we want to declare variables

    strcpy(student1.name, "David");
    student1.age = 52;
    strcpy(student1.Gender, "Male");

    return 0;
}

/*Now with typedef, we dont have to always say "struct student" anymore,
 we can give it a name. It would recognize this name as a structure*/ 

typedef struct {
    char name[50];
    int age;
    char Gender[20];
} Student; 

int main() {
    Student student1;

    strcpy(student1.name, "David");
    student1.age = 52;
    strcpy(student1.Gender, "Male");

    return 0;
}
//you see the difference in declaring the variables? There is no more "struct student"

Crazy right? What I understand barely scratches the surface, but we move! "The pressure is getting wesser"๐Ÿ˜‚. Until next week Thursday.

ย