0% found this document useful (0 votes)
24 views75 pages

PPS Unit 04

Uploaded by

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

PPS Unit 04

Uploaded by

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

“Unit-4”

Structure Data Type


• A structure is a user defined data type that groups logically related data
items of different data types into a single unit.

• All the elements of a structure are stored at contiguous memory locations.

• A variable of structure type can store multiple data items of different data
types under one name.

• The data of employee in company that is name, Employee ID, salary,


address, phone number is stored in structure data type.
Defining of Structure
A structure has to be defined, before it can used. The syntax of defining
a structure is

struct <struct_name>

<data_type> <variable_name>;

<data_type> <variable_name>;

……..

<data_type> <variable_name>;

};
Example of Structure
The structure of Employee is declared as

struct employee
{
int emp_id;
char name[20];
float salary;
char address[50];
int dept_no;
int age;
};
Memory Space Allocation
8000 emp_id
8002 name[20]

8022 salary
8026 address[50]

8076 dept_no
8078 age
Example for sizeof() structure
#include<stdio.h>
struct stud
{
int roll;
char name[10];
int marks;
};
void main()
{
int size;
struct stud s; //Declaring a structure variable
size = sizeof(s);
printf(“\nSize of Structure : %d", size);
}
Size of Structure 'S' = sizeof(roll) + sizeof(name) + sizeof(mark)
= 2 + 10 + 2 = 14
Accessing a Structure Members

•The structure members cannot be directly accessed in the


expression.

•They are accessed by using the name of structure variable


followed by a dot and then the name of member variable.

•The method used to access the structure variables are


e1.emp_id, e1.name, e1.salary, e1.address, e1.dept_no, e1.age.
Initializing a Structure Members
The members of individual structure variable is initialize one by
one or in a single statement. The example to initialize a structure
variable is
1) struct student s = {111,”Sanjana”,558};

2) s.rollno=111
s.name=“Sanjana”
s.marks=558
Example program for structure Initialization
#include<stdio.h>
struct stud
{
int roll;
char name[10];
int marks;
};
void main()
{
int size;
struct stud s={111,"Sanjana",558};
printf("Roll no : %d\n", s.roll);
printf("Name : %s\n", s.name);
printf("Marks : %d\n", s.marks);
}
Example program to read data from keyboard
#include <stdio.h>
struct student scanf("%d", &s.roll);
{ printf("Enter marks: ");
char name[50]; scanf("%f", &s.marks);
int roll; printf("Displaying Information:\
float marks; n");
} s; printf("Name: ");
void main() puts(s.name);
{ printf("Roll number: %d\
printf("Enter information:\n"); n",s.roll);
printf("Enter name: "); printf("Marks: %f\n", s.marks);
scanf("%s", s.name); }
printf("Enter roll number: ");
Structure Assignment
The value of one structure variable is assigned to another
variable of same type using assignment statement. If the e1 and
e2 are structure variables of type employee then the statement
e1 = e2;

assign value of structure variable e2 to e1. The value of each


member of e2 is assigned to corresponding members of e1.
Array of Structure
The array of structure is used to store the large number of
similar records.

The syntax to define the array of structure is

struct <struct_name> <array_name> [<value>];

For Example:-
struct employee e1[100];
Program to implement the Array of Structure
#include<stdio.h>
struct Employee scanf("%d",&Emp[i].Id);
{ printf("\n\tEnter Employee Name : ");
int Id; scanf("%s",&Emp[i].Name);
char Name[25]; printf("\n\tEnter Employee Age : ");
int Age; scanf("%d",&Emp[i].Age);
long Salary; printf("\n\tEnter Employee Salary : ");
}; scanf("%ld",&Emp[i].Salary);
void main() }
{ printf("\nDetails of Employees");
int i; for(i=0;i<3;i++)
struct Employee Emp[ 3 ]; printf("\n%d\t%s\t%d\t
for(i=0;i<3;i++) %ld",Emp[i].Id,Emp[i].Name,Emp[i].Age,
{ Emp[i].Salary);
printf("\nEnter details of %d }
Employee",i+1);
printf("\n\tEnter Employee
Id : ");
Structures within Structures

C language define a variable of structure type as a member of other


structure type. The syntax to define the structure within structure is
struct <struct_name>

{
<data_type> <variable_name>;
struct <struct_name>
{
<data_type> <variable_name>;
……..
}<struct_variable>;
} <variable_name>;
Structures within Structures Example

The structure of Employee is declared as

struct employee

int emp_id; char name[20]; float salary;


int dept_no;
struct date
{
int day;
int month; int
year;
}doj;
}e1;
Accessing Structures within Structures
The data member of structure within structure is accessed by using
two period (.) symbol.

The syntax to access the structure within structure is


struct _var. nested_struct_var. struct_member;

For Example:-
e1.doj.day;
e1.doj.month;
e1.doj.year;
Accessing Structures within Structures
#include <stdio.h> {
#include <string.h> e1.id=101;
struct Employee strcpy(e1.name, "Sonoo
{ Jaiswal");//copying string into char array
int id; e1.doj.dd=10;
char name[20]; e1.doj.mm=11;
struct Date e1.doj.yyyy=2014;
{ printf( "employee id : %d\n", e1.id);
int dd; printf( "employee name : %s\n",
int mm; e1.name);
int yyyy; printf( "employee date of joining
}doj; (dd/mm/yyyy) : %d/%d/%d\n",
}e1; e1.doj.dd,e1.doj.mm,e1.doj.yyyy);
}

void main( )
Union Data Type

•A union is a user defined data type like structure. The union


groups logically related variables into a single unit.
•The union data type allocate the space equal to space need to
hold the largest data member of union.
•The union allows different types of variable to share same space
in memory. The method to declare, use and access the union is
same as structure.
Defining of Union
A union has to defined, before it can used. The syntax of defining a structure
is

union <union_name>

<data_type> <variable_name>;

<data_type> <variable_name>;

……..

<data_type> <variable_name>;

};
Example of Union
The union of Employee is declared as

union employee
{
int emp_id;
char name[20];
float salary;
char address[50];
int dept_no;
int age;
};
Difference between Structures & Union

1)The memory occupied by structure variable is the sum of


sizes of all the members but memory occupied by union
variable is equal to space hold by the largest data member
of a union.
2)In the structure all the members are accessed at any point
of time but in union only one of union member can be
accessed at any given time.
Difference between Structures & Union
Structure Union
You can use a struct keyword to define a You can use a union keyword to define a
structure. union.
Every member within structure is assigned a In union, a memory location is shared by all
unique memory location. the data members.
Changing the value of one data member will Changing the value of one data member will
not affect other data members in structure. change the value of other data members in
union.
It enables you to initialize several members at It enables you to initialize only the first
once. member of union.
The total size of the structure is the sum of the The total size of the union is the size of the
size of every data member. largest data member.
It is mainly used for storing various data It is mainly used for storing one of the many
types. data types that are available.
It occupies space for each and every member It occupies space for a member having the
written in inner parameters. highest size written in inner parameters.
You can retrieve any member at a time. You can access one member at a time in the
union.
Example
Example for sizeof structure and Union
#include <stdio.h>
union unionJob
{
char name[32];
float salary;
int workerNo;
} uJob;
struct structJob
{
char name[32];
float salary;
int workerNo;
} sJob;
int main()
{
printf("size of union = %d bytes", sizeof(uJob));
printf("\nsize of structure = %d bytes", sizeof(sJob));
return 0;
}
Example of Union
#include <stdio.h>
union Job
{
int salary;
int workerNo;
} j;
int main()
{
j.salary = 12000;
j.workerNo = 100;
printf("Salary = %d\n", j.salary);
printf("Number of workers = %d", j.workerNo);
return 0;
}
“Pointers”

26
Pointer Basics
Pointer Definition and syntax

The pointer in C language is a variable which stores the address of


another variable. This variable can be of type int, char, array, or any
other pointer.
Syntax:
Data_type *variable_name;
• Asterisk(*)is called as Indirection Operator. It is also called as
Value at Address Operator.
• It Indicates Variable declared is of Pointer type. variable_name
must follow the rules of an identifier.
Example
int *ip; //pointer to an integer
27 double *dp //pointer to double
Pointer Basics
•Normal variable stores the value whereas pointer variable stores the
address of the variable.

•The content of the C pointer always be a whole number i.e. address.

•Always C pointer is initialized to null, i.e. int *p = null.

•The value of null pointer is 0.

•& symbol is used to get the address of the variable.

•* symbol is used to get the value of the variable that the pointer is
pointing to.

•If a pointer in C is assigned to NULL, it means it is pointing to


nothing.
Pointer concept with diagrams
int i=5;
int *j;
j=&i;
Pointer Basic Example
#include <stdio.h>
void main() q ptr
{
50 5025
int *ptr, q;
q = 50; 5025 5045
ptr = &q;
printf(“Value of q =%d\t", q);
printf(“Address of q =%u\n", &q);
printf(“Address of ptr =%u\t", &ptr);
printf(“Value of ptr =%d", *ptr);
return 0;
}
OUTPUT:
Value of q = 50 Address of q = 5025
Address of ptr = 5045 Value of ptr = 50
Program on Reference and De-reference operator
#include <stdio.h>
int main()
{
int *pc, c=22;
printf("Address of c:%u\n",&c);
printf("Value of c:%d\n\n",c);
pc=&c;
printf("Address of pointer pc:%u\n",pc);
printf("Content of pointer pc:%d\n",*pc);
c=11;
printf("Address of pointer pc:%u\n",pc);
printf("Content of pointer pc:%d\n",*pc);
*pc=2;
printf("Address of c:%u\n",&c);
printf("Value of c:%d\n",c);
return 0;
}
Output
• Address of c: 26867
• Value of c: 22
• Address of pointer pc:26867
• Content of pointer pc: 22
• Address of pointer pc:26867
• Content of pointer pc: 11
• Address of c: 26867
• Value of c: 2

32
Pointer Arithmetic

Pointer Arithmetic on Integers

Pointer Expression How it is evaluated ?


ip = ip + 1 ip => ip + 1 => 1000 + 1*4 => 1004
ip++ or ++ip ip++ => ip + 1 => 1004 + 1*4 => 1008
ip = ip + 5 ip => ip + 5 => 1008 + 5*4 => 1028
ip = ip - 2 ip => ip - 2 => 1028 - 2*4 => 1020
ip-- or --ip ip => ip - 1 => 1020 - 1*4 => 1016

33
Pointer to Pointer
If a pointer holds the address of another pointer then such type of
pointer is known as pointer-to-pointer or double pointer

Syntax:

int **ptr;
34
Pointer to Pointer Example
#include<stdio.h>
void main()
{
int a, *p1, **p2;
a=65;
p1=&a;
p2=&p1;
printf("a = %d\n", a);//65
printf("address of a = %d\n", &a);//5000
printf("p1 = %d\n", p1);//5000
printf("address p1 = %d\n", &p1);//6000
printf("*p1 = %d\n", *p1);//65
printf("p2 = %d\n", p2);//6000
printf("*p2 = %d\n", *p2);//5000
35
printf("**p2 = %d\n", **p2);//65
}
Pointer to Arrays
• When an array is declared, compiler allocates sufficient amount of
memory to contain all the elements of the array.
• Base address i.e address of the first element of the array is also
allocated by the compiler.

Example:

int x[4];

From the above example,


• &x[0] is equivalent to x.
• x[0] is equivalent to *x.
Similarly,
• &x[1] is equivalent to x+1 and x[1] is equivalent to *(x+1).
•36 &x[2] is equivalent to x+2 and x[2] is equivalent to *(x+2).
Example 1: Pointers and Arrays
#include <stdio.h>
int main()
{
int i, x[6], sum = 0;
printf("Enter 6 numbers: ");
for(i = 0; i < 6; ++i)
{
scanf("%d", x+i); // Equivalent to scanf("%d", &x[i]);
sum += *(x+i); // Equivalent to sum += x[i]
}
printf("Sum = %d", sum);
return 0;
}

The program computes the sum of six elements entered by the user.
Example 2: Pointers and Arrays
#include <stdio.h>
int main()
{
int x[5] = {1, 2, 3, 4, 5};
int* ptr;
ptr = &x[2]; // ptr is assigned the address of the third element
printf("*ptr = %d \n", *ptr); // 3
printf("*(ptr+1) = %d \n", *(ptr+1)); // 4
printf("*(ptr-1) = %d", *(ptr-1)); // 2
return 0;
}
Pointers as Function Argument in C
• Pointer as a function parameter is used to hold addresses of
arguments passed during function call. This is also known as call
by reference.
• When a function is called by reference any change made to the
reference variable will effect the original variable.

• The address of num1 and num2 are passed to the swap() function
using swap(&num1, &num2);.

• Pointers n1 and n2 accept these arguments in the function


definition.
void swap(int* n1, int* n2)
{
... ..
}39
Call by Reference Example
#include <stdio.h>
void swap(int *a, int *b); void swap(int *a, int *b)
int main() {
{ int temp;
int m = 10, n = 20; temp = *a;
printf("m = %d\n", m); *a = *b;
printf("n = %d\n\n", n); *b = temp;
swap(&m, &n); //passing address }
printf("After Swapping:\n\n");
printf("m = %d\n", m); Output:
printf("n = %d", n); m = 10
return 0; n = 20
} After Swapping:
m = 20
40 n = 10
Pointer to Structure
Accessing Structure Members with Pointer
• To access members of structure using the structure variable, we used
the dot . operator.
• But when we have a pointer of structure type, we use arrow -> to
access structure members.
Example:
struct person
{ personPtr -> age is equivalent to
int age; (*personPtr).age
float weight;
personPtr -> weight is equivalent to
}; (*personPtr).weight
int main()
{
struct person *personPtr, person1;
} 41
Pointer to Structure Example
#include <stdio.h>
struct my_structure
{
char name[20];
int number;
int rank;
};
int main()
{
struct my_structure variable = {“Sachin", 100, 1};
struct my_structure *ptr;
ptr = &variable;
printf("NAME: %s\n", ptr->name);
printf("NUMBER: %d\n", ptr->number);
printf("RANK: %d", ptr->rank);
42
return 0;
}
Self Referential Structure
Self Referential structures are those structures that have one or
more pointers which point to the same type of structure, as their
member.

In other words, structures pointing to the same type of structures are


43self-referential in nature.
Self Referential Structure Example
void main()
#include<stdio.h>
{
struct node {
struct node ob1;
int data1;
ob1.link = NULL;
char data2;
ob1.data1 = 10;
struct node* link;
ob1.data2 = 20;
};
struct node ob2;
ob2.link = NULL;
ob2.data1 = 30;
ob2.data2 = 40;
ob1.link = &ob2; // Linking ob1 and ob2
/*Accessing data members of ob2 using
ob1*/
printf("%d", ob1.link->data1);
44 printf("\n%d", ob1.link->data2);
}
Enumeration (or enum) in C
Enumeration (or enum) is a user defined data type in C. It is mainly
used to assign names to integral constants, the names make a program
easy to read and maintain.

• To define enums, the enum keyword is used.

Syntax:
enum flag {const1, const2, ..., constN};

By default, const1 is 0, const2 is 1 and so on. You can change default


values of enum elements during declaration (if necessary).
Enumeration (or enum) in C Example
#include<stdio.h> #include<stdio.h>
enum week{Mon, Tue, enum year{Jan, Feb, Mar, Apr, May,
Wed, Thur, Fri, Sat, Sun}; Jun, Jul,Aug, Sep, Oct, Nov, Dec};
int main() int main()
{ {
enum week day; int i;
day = Wed; for (i=Jan; i<=Dec; i++)
printf("%d",day); printf("%d ", i);
return 0; return 0;
} }
Output: 2 Output:
0 1 2 3 4 5 6 7 8 9 10 11
Bitfields in C
Bit Field Declaration
The declaration of a bit-field has the following form inside a structure −
struct {
type [member_name1] : width ;
type [member_name2] : width ;
};

Sr.No. Element & Description


type
1 An integer type that determines how a bit-field's value is interpreted.
The type may be int, signed int, or unsigned int.
2 member_name
The name of the bit-field.
3 width
The number of bits in the bit-field. The width must be less than or
47
equal to the bit width of the specified type.
Bitfields Example
#include <stdio.h>
struct stat{
unsigned int width;
unsigned int height;
} status1;
struct stats{
unsigned int width : 1;
unsigned int height : 1;
} status2;
int main( ) {
printf( "Memory size occupied by status1 : %d\n", sizeof(status1));
printf( "Memory size occupied by status2 : %d\n", sizeof(status2));
return 0;
}
Output:
Memory
48
size occupied by status1 : 4
Memory size occupied by status2 : 1
“Dynamic Memory
Allocation
and
Preprocessor Commands”
49
Dynamic Memory Allocation

The concept of dynamic memory allocation in c language enables


the C programmer to allocate memory at runtime.

Static Memory Allocation Dynamic Memory Allocation

Memory is allocated at compile Memory is allocated at run


time. time.

Memory can't be increased Memory can be increased while


while executing program. executing program.

Used in array. Used in linked list.


Dynamic Memory Allocation
Dynamic memory allocation in c language is possible by 4
functions of stdlib.h header file.

1.malloc()

2.calloc()

3.realloc()

4.free()
malloc()
C malloc()
The name "malloc" stands for memory allocation.
The malloc() function reserves a block of memory of the specified number
of bytes. And, it returns a pointer of void which can be casted into pointers
of any form.
Syntax of malloc()

ptr = (castType*) malloc(size);

Example
ptr = (float*) malloc(100 * sizeof(float));

The above statement allocates 400 bytes of memory. It's because the size of
float is 4 bytes. And, the pointer ptr holds the address of the first byte in the
allocated memory.

The expression results in a NULL pointer if the memory cannot be allocated


malloc() Example
#include <stdio.h>
#include <stdlib.h> printf("Enter elements: ");
void main() for(i = 0; i < n; ++i)
{ {
int n, i, *ptr, sum = 0; scanf("%d", ptr + i);
printf("Enter number of elements: sum += *(ptr + i);
"); }
scanf("%d", &n); printf("Sum = %d", sum);
ptr = (int*) malloc(n * free(ptr);
sizeof(int)); }
if(ptr == NULL)
{
printf("Error! memory not
allocated.");
exit(0);
}
calloc()
C calloc()
The name "calloc" stands for contiguous allocation.

The malloc() function allocates memory and leaves the memory


uninitialized. Whereas, the calloc() function allocates memory and
initializes all bits to zero.

Syntax of calloc()
ptr = (castType*)calloc(n, size);

Example:
ptr = (float*) calloc(25, sizeof(float));

The above statement allocates contiguous space in memory for 25


elements of type float.
calloc() Example
#include <stdio.h>
#include <stdlib.h> for(i = 0; i < n; ++i)
int main() {
{ scanf("%d", ptr + i);
int n, i, *ptr, sum = 0; sum += *(ptr + i);
printf("Enter number of }
elements: "); printf("Sum = %d", sum);
scanf("%d", &n); free(ptr);
ptr = (int*) calloc(n, sizeof(int)); return 0;
if(ptr == NULL) }
{
printf("Error! memory not
allocated.");
exit(0);
}
printf("Enter elements: ");
realloc()
C realloc()

If the dynamically allocated memory is insufficient or more than


required, you can change the size of previously allocated memory
using the realloc() function.

Syntax of realloc()

ptr = realloc(ptr, x);

Here, ptr is reallocated with a new size x.


realloc() Example
#include <stdio.h>
#include <stdlib.h> ptr = realloc(ptr, n2 * sizeof(int));
printf("Addresses of newly
int main() allocated memory: ");
{ for(i = 0; i < n2; ++i)
int *ptr, i , n1, n2; printf("%u\n", ptr + i);
printf("Enter size: "); free(ptr);
scanf("%d", &n1); return 0;
ptr = (int*) malloc(n1 * sizeof(int)); }
printf("Addresses of previously
allocated memory: ");
for(i = 0; i < n1; ++i)
printf("%u\n",ptr + i);
printf("\nEnter the new size: ");
scanf("%d", &n2);
free()

C free()

Dynamically allocated memory created with either calloc() or


malloc() doesn't get freed on their own. You must explicitly use
free() to release the space.

Syntax of free()

free(ptr);

This statement frees the space allocated in the memory pointed by


ptr.
“Preprocessor Directives”
Preprocessor Directives
C PREPROCESSOR DIRECTIVES:
•Before a C program is compiled in a compiler, source code is processed by
a program called preprocessor. This process is called preprocessing.
•Commands used in preprocessor are called preprocessor directives and they
begin with “#” symbol.
Preprocessor Directives
Sr.No. Directive Description

1 #define Substitutes a preprocessor macro.

2 #include Inserts a particular header from another file.

3 #undef Undefines a preprocessor macro.

4 #ifdef Returns true if this macro is defined.

5 #ifndef Returns true if this macro is not defined.

6 #if Tests if a compile time condition is true.

7 #else The alternative for #if.

8 #elif #else and #if in one statement.

9 #endif Ends preprocessor conditional.


#Define and #Include Preprocessors
#define – This macro defines constant value and can be any of the basic
data types.
#include <file_name> – The source code of the file “file_name” is
included in the main C program where “#include <file_name>” is
mentioned.
Example:
#include <stdio.h>
#define height 100
#define letter 'A'
void main()
{
printf("value of height : %d \n", height );
printf("value of letter : %c \n", letter );
} Output:
value of height : 100
value of letter : A
#Define Macro With Parameter
#include <stdio.h>
#define AREA(l, b) (l * b)

int main()
{
int x = 10, y = 5, area;
area = AREA(x, y);
printf("Area of rectangle is: %d", area);
return 0;
}

Output:
Area of rectangle is: 50
#Ifdef, #Else And #Endif Preprocessors
• “#ifdef” directive checks whether particular macro is defined or not.
If it is defined, “If” clause statements are included in source file.
• Otherwise, “else” clause statements are included in source file for
compilation and execution.
Example:
#include <stdio.h>
#define RAJU 100
int main()
{
#ifdef RAJU
printf("RAJU is defined. So, this line will be added in this C file\n");
#else
printf("RAJU is not defined\n");
#endif
return 0; Output:
RAJU is defined. So, this line will be added in this C file
}
#Ifndef and #Endif Preprocessors
• #ifndef exactly acts as reverse as #ifdef directive. If particular macro
is not defined, “If” clause statements are included in source file.
• Otherwise, else clause statements are included in source file for
compilation and execution.
#include <stdio.h>
#define RAJU 100
int main()
{
#ifndef SELVA
{
printf("SELVA is not defined. So, now we are going to define here\n");
#define SELVA 300
}
#else
printf("SELVA is already defined in the program”);
#endif
return 0;
Output: SELVA is not defined. So, now we are going to
define here
}
#If, #Else and #Endif Preprocessors
•“If” clause statement is included in source file if given condition is true.
•Otherwise, else clause statement is included in source file for compilation
and execution.
Example:
#include <stdio.h>
#define a 100
int main()
{
#if (a==100)
printf("This line will be added in this C file since a = 100\n");
#else
printf("This line will be added in this C file since a is not equal to 100\n");
#endif
return 0;
}
Output: This line will be added in this C file
since a = 100
#Undef Preprocessor
This directive undefines existing macro in the program.
Example:
#include <stdio.h>
#define height 100
void main()
{
printf("First defined value for height : %d\n",height);
#undef height // undefining variable
#define height 600 // redefining the same for new value
printf("value of height after undef & redefine:%d",height);
}
Output:
First defined value for height : 100
value of height after undef & redefine : 600
“Command Line Arguments”
Command Line Arguments
• The arguments passed from command line are called command line
arguments. These arguments are handled by main() function.
• The argument values are passed on to your program during
program execution.

Syntax:
int main(int argc, char *argv[])

Where,
1.argc: It refers to “argument count”. It counts the number of
arguments on the command line.

2.agrv: It refers to “argument vector”. It is basically an array of


character pointer which we use to list all the command line arguments.
Command Line Arguments Example
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char * argv[])
{
int i, sum = 0;
if (argc != 3)
{
printf("You have forgot to specify two numbers.");
exit(1);
}
printf("The sum is : ");
sum= atoi(argv[1])+atoi(argv[2]);
printf(“Sum=%d", sum); Output:
return 0; cmd1.exe 10 20
} Sum=30
Command Line Arguments Execution
1. Open Turbo C++.

2. Write a program.

3. Compile and Run your program.It produces the


following result:

“You have forgot to specify two numbers.”

4. Open DOS Shell.


Command Line Arguments Execution
4. Open DOS Shell.
Command Line Arguments Execution
5. Change directory
Now you need to change the current directory of DOS Shell to
"SOURCES" from "BIN", for this you need to user cd command.

First use cd.. for coming back to Turbo C++ main directory

cd..

Now use cd SOURCE to access the SOURCE directory

cd SOURCE
Command Line Arguments Execution
6. Execute Program with Command Line Arguments
“Thank You”

You might also like