Semester : S1 and S2
Subject : Computer Programming
Year : 2018
Term : MARCH
Branch : BIOTECHNOLOGY
Scheme : 2015 Full Time
Course Code : CS 100
Page:15
ret=strncmpi(string1, string2,7); printf("%d",ret);
Output: 0
14.
Type casting is a way to convert a variable from one data type to another data type. For example, if you
want to store a 'long' value into a simple integer then you can type cast ‘long’ to സ്. You can convert the
values from one type to another explicitly using the cast operator as follows -
(type_name) expression
Consider the following example where the cast operator causes the division of one integer variable by
another to be performed as a floating-point operation -
#include
int sum=17, count=5; double mean;
mean = (double) sum / count;
printf("Value of mean : %f\n", mean);
}
When the above code is compiled and executed, it produces the following result -
Value of mean : 3.400000 15.
The most important function of C is main() function. It is mostly defined with a return type of int and
without parameters :
int main() {/* ... */}
Command-line arguments are given after the name of the program in command-line shell of Operating
Systems.
To pass command line arguments, we typically define main() with two arguments : first argument is the
number of command line arguments and second is list of command-line arguments.
int main(int 38५, char *argv[]) {/* ... */ ) or
int main(int argc, char **argv[]) { /* ... */ )
argc (ARGument Count) is int and stores number of command-line arguments passed by the user
including the name of the program. So if we pass a value to a program, value of argc would be 2 (one for
argument and one for program name) 706 value of argc should be non negative.
argv(ARGument Vector) is array of character pointers listing allthe arguments. = argc is greater than
zero,the array elements from argv[0] to argv[argc-1] will contain pointers to strings.
Argv[0] is the name of the program , After that till argv[argc-1] every element is command -line
arguments.
For better understanding run this code on your linux machine.
// Name of program mainreturn.cpp
#include
using namespace std;
int main(int argc, char** argv)
cout << "You have entered " << argc
>> " arguments:" << "\n";
for (int i = 0; 1 < argc; ++i)
cout << argv[i] << "ما"