Vous êtes sur la page 1sur 18

MODEL PAPER - SOLUTION SET

C PROGRAMMING

Marks: 60 Time: 3hours
Noe: !" is #om$u%sor&' Aem$ a(& )our )rom he res'
!"' Aem$ a(& e(' *+,"0-+0.
(a) Gi/e he mea(i(0 o) he )o%%o1i(0 )orma s$e#i)iers:-
2#32432i32u32o32532e32$32s
Ans. The "Format specifier" is the sequence passed as the formatting string argument;
"Characters matched" gives the format of the sequence sought or printed, with a hyperlink to
the section on literals which applies to that format; "Argument type" gives the type of
epression epected !y printf and of pointer epected !y scanf.
6orma s$e#i)ier Chara#ers ma#he4 Ar0ume( &$e
"c any single character char
"d, "i integer integer type
"u integer unsigned
"o octal integer unsigned
", "# he integer unsigned
"e, "$, "f, "g, "% floating point num!er floating type
"p address format void &
"s any sequence of non'whitespace characters char
*7. Gi/e he #%assi)i#aio( o) 4aa &$es i( C'
A(s' Data &$e s$e#i)ies he &$e o) 4aa sore4 i( a /aria7%e' The 4aa &$e #a( 7e
#%assi)ie4 i(o 1o &$es Primii/e 4aa &$e a(4 No(-Primii/e 4aa &$e
PRIMITI8E DATAT9PE
The primitive data types are the !asic data types that are availa!le in most of the
programming languages. The primitive data types are used to represent single values.
I(e0er: This is used to represent a num!er without decimal point.
$g( )*, +,
6%oa a(4 Dou7%e: This is used to represent a num!er with decimal point.
$g( -..), /0.1
Chara#er : This is used to represent single character
$g( 2C3, 2a3
Sri(0: This is used to represent group of characters.
$g( "4.5.6.7.8 6olytechnic College"
:oo%ea(: This is used represent logical values either true or false.

NON-PRIMITI8E DATAT9PES
The data types that are derived from primary data types are known as non'6rimitive data
types. These datatypes are used to store group of values.

The non'primitive data types are
Arrays
5tructure
9nion
linked list
5tacks
:ueue etc
*7.E5$%ai( sr#m$*. a(4 sr#a*. )u(#io(s'
A(s'
strcmp
Syntax:
;include <string.h=
int strcmp> const char &str), const char &str* ?;
The function strcmp>? compares str1 and str2, then returns(
Reur( /a%ue E5$%a(aio(
less than , str) is less than str*
equal to , str) is equal to str*
greater than , str) is greater than str*
For eample(
printf> "$nter your name( " ?;
scanf> ""s", name ?;
if> strcmp> name, "4ary" ? @@ , ?
printf> "Aello, Br. 4aryCDn" ?;
Sr#a is used to concatenate two strings together.
strcat
Syntax:
;include <string.h=
char &strcat> char &str), const char &str* ?;
The strcat>? function concatenates str2 onto the end of str1, and returns str1. For eample(
printf> "$nter your name( " ?;
scanf> ""s", name ?;
title @ strcat> name, " the %reat" ?;
printf> "Aello, "sDn", title ?;
;include<stdio.h=
;include<string.h=
void main> ?
E
char nameF G @ HIilliam 8am!tonJ;
char Ko!F G @ J led the %reat Trigonometrical 5urvey of Lndia.J;
strcat>name, Ko!?;
printf>H"sJ, name?;
M
*# . Di))ere(iae 7e1ee( sru#ure a(4 u(io('
Ans .
Di))ere(#e :e1ee( Su#ure a(4 U(io( :
Sru#ure U(io(
i' A##ess Mem7ers
Ie can access all the mem!ers of structure
at anytime.
Nnly one mem!er of union can !e accessed at anytime.
ii' Memor& A%%o#aio(
4emory is allocated for all varia!les.
Allocates memory for varia!le which varia!le require
more memory.
iii' I(iia%i;aio(
All mem!ers of structure can !e initialiOed Nnly the first mem!er of a union can !e initialiOed.
i/' <e&1or4
PstructP keyword is used to declare structure. PunionP keyword is used to declare union.
/' S&(a5
sru# structQname
E
structure element );
structure element *;
''''''''''
''''''''''
structure element n;
MstructQvarQnm;
u(io( unionQname
E
union element );
union element *;
''''''''''
''''''''''
union element n;
MunionQvarQnm;
/i' E5am$%e
sru# itemQmst
E
int rno;
char nmF.,G;
Mit;
u(io( itemQmst
E
int rno;
char nmF.,G;
Mit;
6i0': Di))ere(#e 7e1ee( Sru#ure a(4 U(io(
*4. =ha are he 4i))ere( sora0e #%asses i( C >
A(s' A storage class defines the scope >visi!ility? and life time of varia!les andRor
functions within a C 6rogram.
There are following storage classes which can !e used in a C 6rogram
auto
register
static
etern
auto - Storage Class
auo is the default storage class for all local varia!les.
E
int Count;
auto int 4onth;
M
The eample a!ove defines two varia!les with the same storage class. auto can only !e used
within functions, i.e. local varia!les.
register - Storage Class
Re0iser is used to define local varia!les that should !e stored in a register instead of SA4.
This means that the varia!le has a maimum siOe equal to the register siOe >usually one word?
and cant have the unary PTP operator applied to it >as it does not have a memory location?.
E
register int 4iles;
M
Segister should only !e used for varia!les that require quick access ' such as counters. Lt
should also !e noted that defining PregisterP goes not mean that the varia!le will !e stored in a
register. Lt means that it 4L%AT !e stored in a register ' depending on hardware and
implimentation restrictions.
static - Storage Class
sai# is the default storage class for glo!al varia!les. The two varia!les !elow >count and
road? !oth have a static storage class.
static int Count;
int Soad;
E
printf>""dDn", Soad?;
M
5tatic varia!les can !e PseenP within all functions in this source file. At link time, the static
varia!les defined here will not !e seen !y the o!Kect modules that are !rought in.
5tatic can also !e defined within a function. Lf this is done the varia!le is initialiOed at run
time !ut is not reinitialiOed when the function is called. This inside a function static varia!le
retains its value during various calls.
void func>void?;

static count@),; R& %lo!al varia!le ' static is the default &R

main>?
E
while >count''?
E
func>?;
M

M

void func> void ?
E
static i @ .;
iUU;
printf>"i is "d and count is "dDn", i, count?;
M

This will produce following result

i is / and count is +
i is 0 and count is V
i is V and count is 0
i is + and count is /
i is ), and count is .
i is )) and count is -
i is )* and count is 1
i is )1 and count is *
i is )- and count is )
i is ). and count is ,
*). =ha are re%aio(a%3 %o0i#a% a(4 7i o$eraors i( C >
A(s'
Re%aio(a% o$eraors
S&m7o% O$eraor E5am$%e
< less than a < W
= greater than a = !
=@ greater than or equal a =@ !
@@ equal to a@@!
C@ not equal aC@!
Lo0i#a% o$eraors
Sam$%e O$eraor E5am$%e
C XNT C>a < !?RTS=
TT AXB a < ! TT c = d
YY NS a YY d
Selational and logical operators evaluate to only a true >)? or false >,? value. Selational
operators have a higher order of precedence that logical operators and therefore are evaluated
first in any epression that includes !oth types of operators.
:i1ise O$eraors
$ach of the !itwise operators affects individual !its in a value. 5ome of these operators are
!inary, taking two !its and returning a third !it. Witwise operators only work on values that
reside in a word or less of storage. Witwise operators cannot !e used with floating point,
dou!le, or long values. The siOe of a word will vary from one machine architecture to
another.
The order of precedence for the !itwise operators is as follows(
Witwise Nperators
O$eraor Des#ri$io( Asso#iai/i&
Z Nnes complement right to left
<< 8eft shift left to right
== Sight shift left to right
T Witwise AXB left to right
[ Witwise #NS left to right
Y Witwise NS left to right
*0 . Gi/e Suia7%e e5am$%es )or $re-4e#reme( a(4 $os-4e#reme( o$eraio(s'
Woth pre'increment and post'increment increment the value. The difference is in what they
return. 6ost'increment returns the original value, while pre'increment returns the incremented
value.
Compound statements such as >!UU? U >UU!? U >UU!? U >UU!? yield 1* when ! is ., !ecause
the evaluation is .U+U+U+ >not .U0UVU+?. This is !ecause pre'increment does not require an
automatic varia!le, so there is no intermediate value >theyPre all incrementing the same value
after all?. To avoid this, you must evaluate each epression separately(
int !@.;
int c@!UU; RR c is ., ! is /
cU@ UU!; RR c is )*, ! is 0
cU@ UU!; RR c is *,, ! is V
cU@ UU!; RR c is *+, ! is +
5imilarly, y@UU & UU evaluates to -+ when is ., !ecause the epression evaluates to 0&0,
not /&0 as might !e epected. Again, the epressions must !e evaluated separately to yield
the epected result(
int @.;
y@ UU; RR y is /, is /
y&@ UU; RR y is -*, is 0
*h. Di))ere(iae 7e1ee( 4o-1hi%e %oo$ a(4 1hi%e %oo$'
A(s'
). Ln while loop the condition is tested first and then the statements are eecuted if
the condition turns out to !e true.
Ln do while the statements are eecuted for the first time and then the conditions
are tested, if the condition turns out to !e true then the statements are
eecuted again.
*. A do while is used for a !lock of code that must !e eecuted at least once.
These situations tend to !e relatively rare, thus the simple while is more commonly
used.
1. A do while loop runs at least once even though the the condition given is false
while loop do not run in case the condition given is false
-. Ln a while loop the condition is first tested and if it returns true then it goes in the
loop
Ln a do'while loop the condition istested at the last.
.. Ihile loop is entry control loop where as do while is eit control loop.
/. 5ynta(
while loop (
while >condition?
E
5tatements;
M
do while loop (
Bo
E
5tatements;
Mwhile>condition?;
>
*i. =ha are ma#ros>
Ans. 4acros arespecial linesRfragments of code written in the source files in the aspect that
itPs not passed to the compiler >either for the purpose of encoding into machine instructions,
or some intermediate form instructions?. Lnstead, macros perform tetual manipulations on
the source code !efore passing it to the compiler, where this process preliminary to compiling
the source files is called "preprocessing", and the software component responsi!le of doing it
is called the "preprocessor". Aenceforth, macros are usually defined as "preprocessor
directives", where a segment of code is replaced !y the results of the macro processing
!efore passing the source code to the compiler. A very valua!le technique to gain a thorough
understanding of the operation of macros in any environment is to learn how to o!tained the
preprocessed source code, and see how the macro directives are epanded.
4acros can !e defined using ;define and undefined using ;undef
The ;define directive has the following synta(
;define identifier replacement-list newline
;define identifier > identifier-list(opt) ?
replacement-list newline
Lf the replacement-list is empty, su!sequent occurrences of the identifier are deleted from the
source file.
The first form of the ;define directive is called an object-like macro. The second form is
called a function-like macro.
The ;undef directive has the following synta(
;undef identifier newline
This directive cancels a previous definition of the identifier !y ;define . Sedefining a macro
previously defined is not legal, unless the new definition is precisely the same as the old.
The replacement list in the macro definition, as well as arguments in a function'like macro
reference, can contain other macro references.
>a? =ha is &$e #asi(0 i( C>
Ans.. C type casting is used to tell the C compiler to treat a varia!le as of a different type in
a specific contet. The compiler will automatically change one type of data into another if it
makes sense. For instance, if you assign an integer value to a floating'point varia!le, the
compiler will insert code to convert the int to a float. Casting allows you to make this type
conversion eplicit, or to force it when it wouldn3t normally happen.
To perform casting, put the desired type including modifiers >like unsigned? inside
parentheses to the left of the varia!le or constant you want to cast.
E5am$%e ":
Consider the code(
float a @ ..*.;
int ! @ >int?a; R&$plicit casting from float to int. The value of ! here is .&R
E5am$%e +:
Consider the code(
char c @ 3A3;
int @ >int?c; R&$plicit casting from char to int. The value of here is /.( the A5CLL
code of 2A3&R
E5am$%e 3:
Consider the code(
char c;
for>c@+0; c<@)**; cUU?
printf>H"c J, c?;
*h. =ha are he a4/a(a0es o) ru((i(0 # i( Li(u5'
A4/a(a0es o) ru((i(0 # i( Li(u5
C is strongly linked with linuRuni .The kernel of 9niR8inu is written in C.Sunning C in
linuRunit has several advantages .The most important among it is full word length
utiliOation.
Consider the following C program
;include
int main>?
E
int a;
float !;
printf>"5iOe of int datatype @"d !itsDn",>siOeof>a?&V??;
printf>"5iOe of float datatype @"d !itsDn",>siOeof>!?&V??;
return );
M
siOeof>? returns the amount of !ytes that the varia!le is awarded
The answer should !e in !its.
After running the a!ove c program in tur!o c in windows
the output will !e
5iOe of int datatype@)/ !its
5iOe of float datatype @1* !its
$ven though computer is 1* or /- !it computer, Tur!o C is utiliOing only )/ !its to int which
should have !een 1* !its>Lnt is allocated with a space equal to wordlength of the computer?
now running the a!ove c program in linu
the output will !e
5iOe of int datatype@1* !its
5iOe of float datatype @/- !its
[[if your processor is 1* !it
5iOe of int datatype@/- !its
5iOe of float datatype @)*V !its
[[if your processor is /- !it
5o, running C program in linuRuni utiliOes full word length. The maimum num!er of
singed int datatype>normal int? that can !e accomodated if the programme is run in c in
windows is >>*[).?')?@3+?6?
that means if PaP is made to store num!er greater than 1*0/0 it will cause data overflow and
user may l get gar!age values
Xow, lets take the scenario in linuRuni
The maimum num!er of singed int datatype>normal int? that can !e accomodated if the c
ode is run c in linu is >>*[1)?')?@+"@?@A36@? >assuming comp is 1* !it?(
5o the int varia!le PaP can store a maimum value of *)-0-V1/-0.
This is for int datatype consider other datatypes such as float,long dou!le,dou!le,long int etc..
5o user can play with larger values if a C program is run in linuRuni.
Apart from this the speed of eecution will !e more than dou!le since it utiliOes full availa!le
word length. 5econdly 8inu is free.
!+' =rie a $ro0ram o sore 4aa o) he Em$%o&ees3 4e$arme( 1ise i( a )i%e' 9ou
shou%4 7e a7%e o 0e(erae he )o%%o1i(0 re$or:- *"0.
*a. Pri( he sre(0h 4e$arme( 1ise'
*7. Pri( he 4eai%s o) hi0hes $ai4 em$%o&ee'
Pro0ram
;include<stdio.h=
;include<conio.h=
RRBepartment Xo ) @@@ Account 5ection
RRBepartment Xo * @@@ Technical 5ection
RRBepartment Xo 1 @@@ AS 5ection
RRBepartment Xo - @@@ 5ecurity 5ection
struct $mployee
E
int empid;
char nameF*,G;
int deptno;
int salary;
Me);
void main>?
E
char ch;
int masal@,;
int empid;
char nameF*,G;
int salary;
int deptno;
int i;
int counter;
FL8$ &fp@fopen>"$mployee.tt","a"?;
clrscr>?;
printf>"DnDnBo you want to enter any record>\RX? "?;
ch@getch>?;
clrscr>?;
while>ch@@PyP YY ch@@P\P?
E
printf>"Dn$nter $mployee LB "?;
scanf>""d",Te).empid?;
fflush>stdin?;
printf>"Dn$nter Xame ( "?;
gets>e).name?;
printf>"Dn$nter Bepartment Xo.>)'-? "?;
scanf>""d",Te).deptno?;
printf>"Dn$nter 5alary ( "?;
scanf>""d",Te).salary?;
fwrite>Te),siOeof>e)?,),fp?;
printf>"DnDnBo you want to enter any more record>\RX? "?;
ch@getch>?;
M
fclose>fp?;
clrscr>?;
fp@fopen>"$mployee.tt","r"?;
while>fread>Te),siOeof>e)?,),fp?@@)?
E
if>e).salary=masal?
E
empid@e).empid;
strcpy>name,e).name?;
salary@e).salary;
deptno@e).deptno;
M
M
printf>"DnAighest 6aid $mployee Dn"?;
printf>"Dn$mployee LB ( "d",empid?;
printf>"Dn$mployee Xame ( "s",name?;
printf>"Dn5alary ( "d",salary?;
printf>"DnBepartment Xo.( "d",deptno?;
fclose>fp?;
getch>?;
for>i@);i<@-;iUU?
E
counter@,;
fp@fopen>"$mployee.tt","r"?;
while>fread>Te),siOeof>e)?,),fp?@@)?
E
if>e).deptno@@i?
counterUU;
M
fclose>fp?;
printf>"DnDnDnBepartment Xo ( "d",i?;
printf>"Dn5trength ( "d",counter?;
M
getch>?;
M
!3 *a. Di))ere(iae 7e1ee( $oi(er a(4 arra&' *+.
A(s' Array is collection of similar datatype. it is a static memory allocation means we can not
increment and decrement the arry siOe once we allocated. and we can not increment
the !ase address, reassign address.
pointer is a dynamic memory allocation. we can allocate the siOe as we want, assigning into
another varia!le and !ase address incrementation is allowed.
3*7. =ha is he 4i))ere(#e 7e1ee( sri(0s a(4 #hara#er arra&s> *3.
The difference !etween string and character arrays is as follows(
A(s'
Sri(0 Chara#er Arra&
). Ln case of string, the compiler
automatically puts null character >2D,3? at
the end of string.
$g(
Char strF.G@Ja!cdJ;
). Ln case of character array, we need to
eplicitly put null character to indicate end
of array.
$g(
Char strF.G@>2a3,3!3,3c3,3d3,3D,3?;
*#. =rie a $ro0ram ha 4&(ami#a%%& a%%o#aes i( i(e0er' I i(iia%i;es he i(e0er
1ih a /a%ue3 i(#reme(s i3 a(4 $ri( he i(#reme(e4 /a%ue' *B.
A(s
include<stdio.h=
;include<conio.h=
void main>?
E
int &ptr;
clrscr>?;
ptr@>int&? malloc >siOeof>int??;
printf>H$nter an integer(J?;
scanf>H"dJ,ptr?;
UU&ptr;
printf>"Lncremented value is("dDn",&ptr?;
getch>?;
M
!@ *a. =rie a C $ro0ram o re/erse he sri(0 1ihou usi(0 srre/*. )u(#io(>
*B.
Ans.
;include <stdio.h=
;include <conio.h=
;include <string.h=
void main>?
E
char strF),G,temp;
int i,len;
printf>"$nter 5tring ( "?;
scanf>""s",str?;
len@strlen>str?');
for>i@,;i<strlen>str?R*;iUU?
E
temp@strFiG;
strFiG@strFlenG;
strFlen''G@temp;
M
printf>""s",str?;
getch>?;
M
*7 . E5$%ai( a(& )i/e )u(#io(s a/ai%a7%e 1ih #&$e'h hea4er )i%e' *B.
A(s' "' The isa%(um )u(#io(
Synopsis
;include <ctype.h=
int isa%(um >int c ?;
Description
The isalnum function tests for any character for which isalpha or isdigit is true.
+' The isa%$ha )u(#io(
Synopsis
;include <ctype.h=
int isa%$ha >int c ?;
Description
The isalpha function tests for any character for which isupper or islower is true, or any
character that is one of an implementation'defined set of characters for which non
of iscntrl, isdigit,ispunct, or isspace is true. Ln the "C" locale, isalpha returns true for only the
characters for which isupper or islower is true.
3' The is#(r% )u(#io(
Synopsis
;include <ctype.h=
int is#(r% >int c ?;
Description
The iscntrl function tests for any control character.
@' The is4i0i )u(#io(
Synopsis
;include <ctype.h=
int is4i0i >int c ?;
Description
The isdigit function tests for any decimal'digit character >as defined in AX5L C section
..*.)?.
B' The is0ra$h )u(#io(
Synopsis
;include <ctype.h=
int is0ra$h >int c ?;
Description
The isgraph function tests for any printing character ecept space >P P?.
!B *a. =ha are )u(#io(s i( #> *B.
A(s' 6u(#io(s i( C:
The function is a self contained !lock of statements which performs a coherent task of a same
kind.
C program does not eecute the functions directly. Lt is required to invoke or call that
functions. Ihen a function is called in a program then program control goes to the function
!ody. Then, it eecutes the statements which are involved in a function !ody. Therefore, it is
possi!le to call fuction whenever we want to process that functions statements.
T&$es o) )u(#io(s:
There are *>two? types of functions as(
"' :ui% i( 6u(#io(s
+' User De)i(e4 6u(#io(s
"' :ui% i( 6u(#io(s:
These functions are also called as Pli!rary functionsP. These functions are provided !y system.
These functions are stored in li!rary files. e.g.
scanf>?
printf>?
strcpy
strlwr
strcmp
strlen
strcat
"' User De)i(e4 6u(#io(s:
The functions which are created !y user for program are known as P9ser defined functionsP.
S&(a5:
/oi4 main>?
E
RR Function prototype
<returnQtype=<functionQname=>F<arguQlist=G?;
RR Function Call
<functionQname=>F<arguments=G?;
M
RR Function definition
<returnQtype=<functionQname=>F<arguQlist=G?;
E
<functionQ!ody=;
M
Pro0ram:
R& 6rogram to demonstrate function.
Creation Bate( *1 Xov *,), ))(1)(*, A4
Author ( www.technoeam.com FTechnowell, 5angliG &R
;include <stdio.h=
;include <conio.h=
/oi4 add>?
E
i( a, !, c;
clrscr>?;
printf>"Dn $nter Any * Xum!ers ( "?;
scanf>""d "d",Ta,T!?;
c @ a U !;
printf>"Dn Addition is ( "d",c?;
M
/oi4 main>?
E
/oi4 add>?;
add>?;
getch>?;
M
*7. Di))ere(iae 7e1ee( #a%% 7& /a%ue a(4 #a%% 7& re)ere(#e )u(#io(' *B.
A(s:
Ca%% 7& 8a%ue( Ln this method, the values of the actual parameters are copied to the
varia!les in the parameter list of the called function. The called function works on the copies
of the varia!les and not on the actual parameters. Therefore, the changes are not reflected
!ack on the actual parameters.
$ample(
void sum>int ,int ?;
void main>?
E
int a,!;
printf>HDn$nter two integers ( H?;
scanf>H"d"dJ,Ta,T!?;
printf>HDnWefore swap the value of A @ "d, W @ "d J,a,!?;
swap>a,!?;
printf>HDnAfter swap the value of A @ "d, W @ "d J,a,!?;
M
void sum>int p),int p*?
E
int temp @ p);
p)@p*;
p*@temp;
M
Ca%% 7& Re)ere(#e( Ln this method, the memory address of the varia!les, rather than
the copies of the varia!les are send to the called function. Ln this method, the called function
directly works on the data in the calling function. The changes made in the values of actual
arguments are availa!le in the calling function for its use.
$ample(
void sum>int &,int &?;
void main>?
E
int a,!;
printf>HDn$nter two integers ( H?;
scanf>H"d"dJ,Ta,T!?;
printf>HDnWefore swap the value of A @ "d, W @ "d J,a,!?;
swap>Ta,T!?;
printf>HDnAfter swap the value of A @ "d, W @ "d J,a,!?;
M
void sum>int &p),int &p*?
E
int temp @ &p);
&p)@&p*;
&p*@temp;
M
!6' E5$%ai( $ro#ess a(4 )u(#io(s o) )ork*. a(4 e5e#*. i( Li(u5' *"0.
Ans. $very running instance of a program is known as a process. The concept of processes is
fundamental to the 9XL# R 8inu operating systems. A process has its own identity in form
of a 6LB or a process LB. This 6LB for each process is unique across the whole operating
system. Also, each process has its own process address space where memory segments like
code segment, data segment, stack segment etc are placed. The concept of process is very
vast and can !e !roadly classified into process creation, process eecution and process
termination.
fork>? function and how it works.
The )ork*. 6u(#io(
The fork>? function is used to create a new process !y duplicating the eisting process from
which it is called. The eisting process from which this function is called !ecomes the parent
process and the newly created process !ecomes the child process. As already stated that child
is a duplicate copy of the parent !ut there are some eceptions to it.
The child has a unique 6LB like any other process running in the operating system.
The child has a parent process LB which is same as the 6LB of the process that created
it.
Sesource utiliOation and C69 time counters are reset to Oero in child process.
5et of pending signals in child is empty.
Child does not inherit any timers from its parent
E5e#*. 6u(#io(
The eec>? family of functions replaces the current process image with a new process image.
The functions descri!ed in this manual page are front'ends for eecve>*?. >5ee the manual
page for eecve>*? for further details a!out the replacement of the current process image.?
The initial argument for these functions is the name of a file that is to !e eecuted.
The const char &arg and su!sequent ellipses in the eecl>?, eeclp>?, and eecle>? functions
can !e thought of as arg,, arg), ..., argn. Together they descri!e a list of one or more pointers
to null'terminated strings that represent the argument list availa!le to the eecuted program.
The first argument, !y convention, should point to the filename associated with the file !eing
eecuted. The list of arguments must !e terminated !y a X988 pointer, and, since these are
variadic functions, this pointer must !e cast >char &? X988.
The eecv>?, eecvp>?, and eecvpe>? functions provide an array of pointers to null'
terminated strings that represent the argument list availa!le to the new program. The first
argument, !y convention, should point to the filename associated with the file !eing
eecuted. The array of pointers must !e terminated !y a X988 pointer.
The eecle>? and eecvpe>? functions allow the caller to specify the environment of the
eecuted program via the argument envp. The envp argument is an array of pointers to null'
terminated strings and must !e terminated !y a X988 pointer. The other functions take the
environment for the new process image from the eternal varia!le environ in the calling
process.
S$e#ia% sema(i#s )or e5e#%$*. a(4 e5e#/$*.
The eeclp>?, eecvp>?, and eecvpe>? functions duplicate the actions of the
shell in searching for an eecuta!le file if the specified filename does not contain a slash >R?
character. The file is sought in the colon'separated list of directory pathnames
specified in the 6ATA environment varia!le. Lf this varia!le isnPt defined, the path list
defaults to the current directory followed !y the list of directories returned
!y confstr>QC5Q6ATA?. >This confstr>1? call typically returns the value "R!in(RusrR!in".?
Lf the specified filename includes a slash character, then 6ATA is ignored, and the file at the
specified pathname is eecuted.
Ln addition, certain errors are treated specially.
Lf permission is denied for a file >the attempted eecve>*? failed with the error $ACC$5?,
these functions will continue searching the rest of the search path. Lf no other file is found,
however, they will return with errno set to $ACC$5.
Lf the header of a file isnPt recogniOed >the attempted eecve>*? failed with the
error $XN$#$C?, these functions will eecute the shell >R!inRsh? with the path of the file as
its first argument. >Lf this attempt fails, no further searching is done.?
Reur( 8a%ue
The eec>? functions only return if an error has have occurred. The return value is '),
and errno is set to indicate the error.
Errors
All of these functions may fail and set errno for any of the errors specified for eecve>*?.

Vous aimerez peut-être aussi