← Previous lessonFree lesson 3 of 3 · lesson 3 of 62

Unlock all 62 lessons of C Programming for Telecom Engineers and C++ OverviewFull course ₹40,000 · paid

Price & syllabus
Free lesson · 26 min · no payment

C Variables, Data Types, Memory Layout and Storage Classes

A free lesson from Skill-Lync's C Programming for Telecom Engineers and C++ Overview course, on Grow by Skill-Lync · Last updated 16 Nov 2026 · Session: “C Variables and Basics for Telecom Engineers”

What will you learn in this free C Programming for Telecom Engineers and C++ Overview lesson?

The instructor covers variable naming rules and the main C data types with their sizes (int 4 bytes, char 1, double 8, short 2, long 8), then demonstrates sizeof and format specifiers in a compiled program. The lesson explains the memory layout of a C program and the auto, register, static and extern storage classes, with an example of a static variable keeping its value.

  • Variable naming rules in C
  • Data type sizes and format specifiers
  • Text, data, heap and stack segments
  • auto, register, static and extern keywords

What comes after lesson 3?

Later in Skill-Lync's C Programming for Telecom Engineers and C++ Overview course (paid): lesson 4, Understanding Variable Storage Classes in C; lesson 5, C Programming Basics Part 2; lesson 6, Understanding while and do-while loops. The full course has 62 lessons (28 h 29 min of video); see the course overview or its price and syllabus.

Lesson transcript

Machine transcript of the lesson audio (lightly cleaned). Technical terms may contain errors; the video is the reference.

Hello everyone. Welcome back to the course C Programming for Telecom Engineers. This is our week 1 and today we will be starting with the C basics. So this basics we have divided into two portions. So today we will be discussing the part 1. So let's just quickly recap whatever we discussed in the last session. In the last session we discussed about the Linux. What is a Linux operating system? What is it built upon? And what are the features of Linux operating systems? What is a Linux kernel? How it interacts with the hardware and gives you the availability of the hardware in your user space?

Okay. Then we went through various basic commands in the Linux, what we use and what we need to use. Okay. On a daily basis like CP, MV, LS, all those commands. Okay. Then to run those commands, we installed Linux Ubuntu Linux on the Windows itself. So we also went through the procedure. How can we install Ubuntu on Windows itself? Okay. Okay. And then we discussed about VIM editor. So VI editor and VIM editor. So this is used to edit anything, to write a code or to write anything. We use this VI improved editor which is called VIM editor.

Then we went through like a few VIM editor. Then we went through like a few of the VIM commands, important commands like how to edit, how to insert, how to quit, how to, you know, grab and all those things. Okay. Then we went through the GCC introduction where we understood what is a GCC and how do we compile a code using the GCC compiler. Okay. Then we just, we edited, I mean, we wrote one of the code, the first code of C in VIM editor. Okay. And we executed using the GCC compiler. All right.

So these are the table of contents for today's session. So we'll, we'll discuss about C variables. The, what, what is a C variable? How it is declared? What are the, you know, guidelines to declare variables? Then we'll discuss about various data types available in C. Then we'll see the memory layout of a C program. I mean, when the C program executes, then what variables, what data types gets memory from which location and what, what is the layout of that memory in a C program. Then we'll discuss about a storage class. Part of this, we'll discuss four storage classes, auto, static, external, and registered. Okay.

Then we'll see what is a local variable, global variable, static variable, and the difference between local and global, global and static and global static. Okay. And then we'll see how this static variable is being used in the telecom domain. How LTE code uses static variable and what is the importance of having this static variable in a code. Then we'll discuss how to take input in a C program and then how to print it, how to, you know, send the output to the standard out. Okay. And then we'll summarize whatever we will be discussing today.

Okay. So this week, we'll learn about C variables, C data types, the memory layout of a C program, storage class, local versus global, and local versus static. A static variable uses in telecom, how this static variable is being used in the telecom code base, in the industrial code base. Okay. And then we'll discuss, I mean, we'll learn how to take input and how to print outputs on the console in C programming. So let's start with our topic, C variables. It is a storage area which is used to hold the data.

So any variable is used to hold the value of a data. Okay. So let's say I have to assign some value. Let's say I have to assign 5, role number 5 to a student. Okay. In the code, then I need to use a variable, maybe a role number, role num, or any kind of name we can give it and we can assign that value. value so that that particular variable will hold the sum section in the memory. Okay. It will just take some memory and it will put the actual value over there.

So this variable is used to, you know, access it. If you have to access that memory area, you can use that variable. I mean, through that variable, you can access that memory area. So these are the naming conventions, a variable name consists of alphabets, both upper and lower case. Okay. Digits and a underscore. So these are the only possibilities. So there are no any other special characters. You cannot use a star. You cannot use a dollar. You cannot use a percentage. Okay. In the name of the variable, a variable name must not start with a digit.

So it contains a digit. Okay. I mean, it may contain a digit. Okay. But it should not start. It must not start with a digit. It has to be always start with an alphabet, whether it could be a upper case or it could be a lower case. No white spaces allowed in the name of a variable. If you are declaring a variable, for example, role number, then you have to use either role number continuously or you can put a role underscore number like that. But you cannot declare like int role space number.

Okay. For example, here you can see int my var 2. So my var 2 here is I could have given a space, but that will be wrong. You cannot give a space over here between my and var 2. Okay. So what you can do, you can give an underscore, my underscore var 2 equals to 25. So I mean, during the declaration, we can assign some value as well. Similarly, int my underscore var 4. So here you can see in both the variables I have used a digit and this variable var 4 contains a uppercase letter.

Okay. And both contains an underscore, but it doesn't contain any of the other special characters. Okay. And also my variable name is not starting with a digit. All right. If you start with any of the digit, if you put any star or percentage or dollar, hash, anything, that will be wrong. That is not acceptable in C programming. Now, next is C data types. So these are the main important data types. There are a few more. Okay. But these are the main data types. So first is int used to store integer.

Okay. So the size of int is 4. So let's say I am declaring one integer, let's say roll number. So it is going to take 4 bytes from the memory. Okay. It will be 4 bytes. And the format specifier, we'll see what is a format specifier. As of now, you just remember that this is the format specifier used for int. That is %d. Okay. Next is char. Char is used to store one character. It could be like a, b, c, d kind of character or any special character as well.

So the number of bytes it takes in the memory is 1. 1 byte it takes in the memory. And %c is the format specifier. Okay. Next is float. Float is basically used to hold real numbers. Real numbers means the decimal numbers. Okay. So 5.666, 5.3, 3.999 kind of number if you have to store, you should use the float. Okay. Double is also used to hold the real numbers. Okay. But here you can see the difference is between float and double is the memory size. If you have a lower number.

Okay. Then you can use float as it takes 4 bytes. But if you have a big number. Okay. Then you can use this double, 8 bytes. Okay. And the format specifier is %f for float and %if for double, %lf for double. Okay. That is called long. Then short int. Short int is also used to hold a integer. Okay. But here the difference is the integer, the regular integer size is 4 bytes in the memory. But short integer size is 2 bytes in the memory. Okay. So again, it is used to hold a short integer.

So 2 bytes, it can hold 16 bits. So the maximum value, whatever can be accommodated in 16 bits, I mean all 16 bits 1, that will be the maximum value you can store in the short int. So if you have to use more than that, then you have to go with the regular int, which takes size as 4 bytes. Then unsigned it. So by default an integer int is unsigned. Sorry. It's signed. Signed means it can also hold a negative value. But unsigned int, it will always have the positive.

It will hold either 0 or positive value. Okay. So percentage use is used as a format specifier. And the size is still same. Okay. This is 4 bytes only as per the normal integer size. Next is long int. Long int is again. It's an extensive version of integer int. So the difference between long int and short int, long int and int is, integer takes 4 bytes and long integer takes 8 bytes. So if you have a very small size integer you have to store, you can go with short int.

Okay. Then if it is going beyond 2 bytes, you can go for either unsigned int if it is always going to be a positive value. If it is going to be a negative value as well, you can go for int. Okay. And if it has to go beyond 4 bytes, then you can go with long int which holds 2 bytes. Okay. So let's see one example that code 1.c. So this code you can refer anytime. Okay. It will be available with you. So let's go with this 1.c. And we'll see the usage along with this format specifiers. Okay. Of all these data types.

And also we'll see the sizes. Okay. All right. So here you can see I have kept all the data types int a equals to 5. Okay. Okay. Then char b equals to z. That is so character has to be declared and defined like this. You have to put a single quote. Okay. So you can put any in character a, b, c like. Then float c. Float c is 5.4 and double d 7.333, 3, 3, 3, 3, 4, 5. Short int e equals to 2 and unsigned int f equals to 11. Long int g equals to 15. Okay.

So I have taken all the data types whatever we discussed just now. Okay. And I have tried to print with the format specifier. So format specifier is basically this. So once we'll understand this print f and scan f later on in this session. We'll discuss it in detail. But you can see here to use different type of data types. Okay. A, b, c, d, e, f, g. Okay. I have used different format specifier. For example, %d is for a for integer. %c is for character. %f is for float. Lf is for double. %u for unsigned int. Okay. %ld for long int.

Now I have put another print of size. Okay. Size is I mean I have kept every data type size here. Size of a, b, c, d, e, f, g. So this is a system call. This is a library call nc programming which is already defined. Okay. You can simply just wrap it and you can call it size of a. So the a data type is integer. It will give you the size of integer. Either you can use size of a or you can also use size of int. Okay. Instead of a, you can put int. Similarly, size of b. Instead of b, you can put size of char. Okay.

So let me run this program. Okay. So I have just opened another terminal to run this program so that I can show you the output along with the code. Let me compile this 1.c. Okay. It is compiled. Now I will run this. Okay. So now you can see here. The values a, b, c, d, e, f, g. Okay. Here 5, z, 5.4. So whatever I had initialized with. Okay. Whatever I had initialized, the same thing has been printed out here. But the next line, right, you can see the sizes. So size of a, size of integer 4, size of b, character 1, size of c, float 4.

Size of d, double, 8. Size of e, that is short int, right. So short int is 2. Size of f, f is your unsigned it. Unsigned it is again 4. It's same to the int. And size of g, size of g is long int. So it has to be 8. So this is how you can print it. Okay. Similarly, if I change this code. Okay. If I simply change this code with not giving the name of the variable, I'll simply give the int. For the int, size of int. And b is size of car. And for the float, here I'll give size of float. Okay. For the double, I'll give size of double. And then short int. So here I can give a size of short int. Okay.

And unsigned int and long int. Signed int and long int. Long int. Okay. So there are various ways. I mean, this is another way. You can check the size of the data type. I mean, if you are not sure or you may need in some of the operations, you may need have to allocate the memory, but you don't know the size, what is going to be. Then you can use the size of operator to get the size of the data type. And that many number of, for example, you have to allocate for five integers.

So you can simply use five into size of int. And you can sometimes this size also varies based on the platform. Different platforms may give you the different sizes. So you can always check the size of all the data types using the size of operator. Okay. Let me again compile this. Yeah. So here you can see this was the previous one. Okay. And this is the one we have added. So you can see the exact size we have got. Okay. So this is how we get the size of the code. And these are the data types, which is having the sizes. And you can always get the sizes using the size of operator.

Also, the format specifier you saw, right? Like how do we use it for different type of data types. Now, next is C program memory layout. Okay. So this is the whole memory layout. So whenever you execute a C program, okay, so it creates a layout like this. Okay. In the memory section. So what it does, it creates the text segment, initialized data segment, initialized data segment, heap and stack. So this portion is dynamic. This portion keeps on increasing. It comes down. It goes up. Okay. So stack size may increase or reduce. Heap size also may increase, reduce based on the requirement. Okay.

Based on the allocation, dynamic allocation happening in the program. So the text size is used to store all the text from the program. Okay. And this data segment, okay, data segment is used to store any of the global variable. Okay. Global variable or any of the static variable. So there are two sections here. One is uninitialized and one is initialized. So if you are initializing the data at the time of declaring, it goes inside initialized data segment. And if you don't initialize, if you don't initialize any data, just declare it as global or static.

It goes in the uninitialized data segment. Okay. The stack is all the functions, all the local variables in a function who goes inside the stack. Okay. And all the dynamically allocated memory. Okay. It goes inside heap. So why this two, both the sections are variable? Because the function memory, let's say you have a main function and from main function, you are calling another function. So when you call that function, I mean the execution, when the execution starts of that function, then only the memory gets allocated from the stack.

Once the execution will finish of that particular function, then again the stack, all the variable which was local in the function was allocated from the stack segment will be destroyed. And stack will again shrink back. Okay. That's the reason stack is dynamic, the stack memory segment. Heap is also dynamic because whenever you are allocating any memory dynamically, dynamically means it is like not having a static memory, like not having an array kind of or not having a variable. You are dynamically at the runtime while allocating the memory.

That also comes from heap. That's the reason this is also dynamic. Okay. I mean, this is also variable. So these two sections are variable, right? Next is storage classes. Okay. There are four storage classes in C. One is auto, register, static, and external. So auto is, I mean, all the variables by default is auto. Also called local. For example, if you are declaring a variable int p equals to 8. Okay. So either you declared like int p equals to 8 or you can add auto int p equals to 8.

Both statements are same. Okay. So by default, that's the reason these variables are called by default because the other storage classes need special, you know, keyword to be added with that particular variable. So if you don't add any keyword, it becomes auto. So these are all your local. MATLABs are auto. Then the register. Register is basically, it stores the memory from the CPU registers, not from the main memory. CPU register for the fast accessing. So, for example, you are having a loop of some thousands or more than 10Ks kind of loop.

Okay. So, the index, for example, i equals to 0 to 1 lakh. So, that index i has to be, you know, accessed very frequently. So, those kind of variables are made register. So, register int c equals to 9. If you add this register keyword, this int c, the c variable will be stored in the register. But, that is not guaranteed. It depends on the compiler. I mean, if it is available, then only it will be given from register or else it will be just given from the main memory. So, you cannot make sure that always you will get from the register.

But, this is used for the fast accessing. Next is static. Static, preserving their value even after they are out of their scope. Out of their scope means, as just now we discussed, like, if you are having a function f, okay, and there you have int a, int b. And, once the execution will finish of that function, this a and b will be destroyed. Again, if you are calling back that function f, then again a and b will be initialized back. So, let's say, let's say, for example, you have done like something int a equals to inside a function, okay, if you have done like this, you have one int a equals to 10 and int b equals to 15, okay, and you have one static int b equals to 10, okay.

So, for example, if you have this kind of scenario and from the main function, okay, from the main function, you are calling your function fun, okay. So, once the fun execution will start, okay, this memory will be allocated from the stack int a and b, okay. But, this memory, static int, will come from the data segment, okay. That is why static is spatial and data segment persists till the program executes, okay. It's not like once the function execution will finish, the data segment will be gone.

It's not like that. But, the local variables, the stack variables, this will go off. So, if you are calling again fun, okay, this will, for example, if you make it like a plus plus, okay, b plus plus and b plus plus, okay. If you print here, okay, if you print here, okay, this a, b and p, then a will print 11, b will print 16 and p will print 11, okay. Normal execution. But, if you, once the execution will finish, again, if you are calling back this function, then a and b will be initialized with 10, 15 back.

But, p will not be initialized because it is in data segment. It was not destroyed at that time, okay. So, a plus plus will, b plus plus will again become 11 and 16. But, p plus plus will become, become now 12 because it was 11 in the last execution. So, that is the main difference. That is what we call as the static variable is persistent, okay. For example, you can add this keyword static int c, okay. And, also, one more application of static variable is like, if you are declaring any function as static, okay, then that function cannot be used from outside.

Outside means from other file, okay. So, basically, in a project, what happens, you have always multi-file applications. You have so many files in place, okay, maybe 100 of files and each file is, will be calling functions available in other file. So, for the privacy, for the, some security perspective, if you want to make, you know, some function very private to that file, if you don't want that function to be accessed outside the file from some other file, then you can make that static. So, a static function cannot be accessed from outside the file.

Next is extern. So, let's say if you are, you know, using a global variable, if you are having a global variable, then in one file, and if you want to use that global variable in other files, so you cannot simply use that file, I mean, that variable. It will be, you know, it will give you a compilation error saying that this variable is not declared. For example, in a.c, you declare int var1, okay. And in b.c, if you are trying to use it, because it is a global variable, you should be using it in the entire program, right?

You can use from anywhere. But if you use like this, compiler will not understand whether it was a global or it was a local variable, right? So, for that, you have to make the compiler understand using extern keyword. So, if you use this extern int c in, let's say, file b.c, then it will not give you a compilation error. And the compiler will understand that this int c was already declared globally in some other file, okay? So, that is how extern is used.

Want the rest of C Programming for Telecom Engineers and C++ Overview?

Get the full course syllabus and fees.

The full course is paid (₹40,000). We'll send the syllabus and call you back within one working day.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Full course · paid

Unlock the full C Programming for Telecom Engineers and C++ Overview course

The remaining 59 lessons, mentor-reviewed projects and a certificate come with the paid course (₹40,000). Leave your details: we'll send the syllabus and fees and call you back.

Get the syllabus and fees

A counsellor calls you back within one working day.

By submitting you agree to our Terms and Privacy Policy.

Grow by Skill-Lync · free lesson

Start watching

Free, no payment. Leave your details once and every free lesson on Grow plays straight away. A Skill-Lync counsellor may call you about the full C Programming for Telecom Engineers and C++ Overview course.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.