0% found this document useful (0 votes)
3 views6 pages

COAL Lab 1

This document provides a step-by-step guide on downloading and installing the GCC-w64 version 14 for Windows, including setting environment variables. It also explains how to create and compile a simple 'Hello World' program in C, detailing the phases of converting C code into executable code. Additionally, it includes code snippets for printing the memory representation of C variables.

Uploaded by

sarah.ayyazzzz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

COAL Lab 1

This document provides a step-by-step guide on downloading and installing the GCC-w64 version 14 for Windows, including setting environment variables. It also explains how to create and compile a simple 'Hello World' program in C, detailing the phases of converting C code into executable code. Additionally, it includes code snippets for printing the memory representation of C variables.

Uploaded by

sarah.ayyazzzz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

How to download & install GCC -win64 version 14 for Windows Operating System.

Step # 1

You need to download gcc-win64 latest version for Windows 10/11. For that just go to the
following link: https://sourceforge.net/projects/gcc-...

This page will lead to the gcc-win64 for Windows Sourceforge download page.

Step # 2

Install gcc-win64 Double-click to run the gcc-win64 installation file. and install MinGW-w64 on
your OS.

❖ Goto download directory and extract the zip file


❖ Rename it as gcc-12.5.0
❖ Then cut this folder and paste it in c drive.

Step # 3

Now you need to set the environment variables,

❖ inside the gcc 12.5.0 folder go to bin folder.


❖ Right click & Copy the path
❖ Just go to search and type Environment
❖ Click edit the system Environment variable
❖ In system property windows go to Environment Variables
❖ In the current window click on path and click on Edit.
❖ Now click on New option and paste the path that we copy earlier in bin folder.
❖ Click ok and close the directory.
❖ Now again go to search and type cmd
❖ Type a command on command prompt Gcc --version

Now gcc compiler installed successfully.


If you find any error like GCC is not recognized as an internal or external command so its
basically means that gcc is not properly installed on system. So set environment path properly
to avoid these kind of errors.

How to Create your First Hello World Program in C programming and how to compile and run
on the command Line Interface.

• Make a folder on Desktop e.g named c programs


• Add new text file and change its file extension from .txt to .c
• Add code

#include<stdio.h>

int main()

printf("Hello World");

return 0;

• Run cmd
• Gcc filename.c & enter
• Write .exe file name
Steps to convert c program into executable code.

1. Pre-processing
This is the first phase through which source code is passed. This phase includes:

• Removal of Comments
• Expansion of Macros
• Expansion of the included files.
• Conditional compilation

2. Compiling
The next step is to compile filename.i and produce an; intermediate compiled output
file filename.s. This file is in assembly-level instructions.

3. Assembling
In this phase the filename.s is taken as input and turned into filename.o by the
assembler. This file contains machine-level instructions. At this phase, only existing
code is converted into machine language, and the function calls like printf() are not
resolved.

4. Linking
This is the final phase in which all the linking of function calls with their definitions is
done.

#include <stdio.h>
int main(){

//value and address of variable


int x=5;
printf("The value of x is %d\n",x);
printf("the address of x is %p\n", &x);
//size of data types
printf(" the size of int is : %zu\n",sizeof(int));
printf(" the size of float is : %zu\n",sizeof(float));
printf(" the size of character is : %zu\n",sizeof(char));
printf(" the size of short is : %zu\n",sizeof(short));
printf(" the size of long long is : %zu\n",sizeof(long long));
printf(" the size of long is : %zu\n",sizeof(long));
// typedef
// typedef existingtype newtype
typedef int integer ;
integer n=100;
printf("Value of n is %d\n", n);
return 0;

}
How to print the memory representation of C variables. Here we will show
integers, floats, and pointers.
❖ Get the address and the size of the variable
❖ Typecast the address to the character pointer to get byte address
❖ Now loop for the size of the variable and print the value of typecasted
pointer.

#include <stdio.h>
typedef unsigned char *byte_pointer; //create byte pointer using char*
void disp_bytes(byte_pointer ptr, int len) {
//this will take byte pointer, and print memory content
int i;
for (i = 0; i < len; i++)
printf(" %.2x", ptr[i]);
printf("");
}
void disp_int(int x) {
disp_bytes((byte_pointer) &x, sizeof(int));
}
void disp_float(float x) {
disp_bytes((byte_pointer) &x, sizeof(float));
}
void disp_pointer(void *x) {
disp_bytes((byte_pointer) &x, sizeof(void *));
}
int main(){

int i = 5;
float f = 2.0;
int *p = &i;
disp_int(i);
printf("\n");
disp_float(f);
printf("\n");
disp_pointer(p);
printf("\n");
disp_int(i);

return 0;
}

You might also like