S
sophia.agnes
Dear all,I was going through a C book written by an indian author
the following are the questions given in that book
Would be interesting for me to know which book this is ?
1) consider the following statement:
s1 : an operator may require an lvalue operand, yet yield an r
value
To be specific , the question applies to unary operators only ? Then the &
operator is one such:
&n is a an rvalue. For a binary operators I can think of a == b
2) which of the following is falsea) a string has type array of characters /* it is meant string literals ?*/
b) a string has storage class static /* it is meant string
literals have internal linkage */
c) adjacent string literals are concatenated into a single string
d) Concatenation of ordinary and wide string literal is a single
stringanswer is given as d option3)consider the followingprocess1(int counter)
{if(counter == 1)
{
char buf[80];process2(int counter)
{
char buff[80];
if(counter == 1)
{
--------
}
which one of the following is true(a) both process require same stack space in all cases
(b) process 1 require more stack space
(c) process 2 require more stack space
(d) stack space for process is not allocated if counter == 1answer is given as a option
most architectures use something like a stack for automatic storage.
but i am not sure if this answer is correct..
4) consider the following statementss1: evaluating the address of an object value after indirection is
simply object
s2:evaluating an object value from indirecting after taking its
address is not the object
*&(x) == x and &*(x) != x
Is this what is meant by the complicated language ??
which of the following is true
(a) only s1
(b) both are correct
(c) only s2 is correct
(d) both are wronganswer is given as b option5)which operation require more memory access
(a) branch
(b) conditional code test
(c) shift register right /* what is this ?*/
(d) all are sameanswer is given as d option
Not a C question. But since none of the instructions are load-store, they
dont do memory access,
the answer is (d).
well what do you folks think of all this stuff ?
Good for embedded programming job interview in india
The book name is Advanced test in C
and
Embedded System Programming !!!!!!!!!!!
by Ashok .K pathak
some more questions from the book
state whether true or false
1) system can't determine size of the stack before program runs
answer is given as true
2) location of constant string in memory(text area or data area)
may be compiler dependent
answer is given as true
string may be placed in data area of string area depending on
implementation
3)in all cases printf(ptr); and printf("%s",ptr); will print the same
string,where ptr points to the address of the string
answer is given as false
printf(ptr); fails if ptr contains %
ex:- printf("a%cb"),printf("%s","a%cb"); will print different
strings
4) which of the following is false
(a) a reentrant function may not use variable in a non atomic way
unless they are stored on the stack of the task that called the
function or are other wise the private variable of that task
(b) a reentrant function may not call any other function that are
not reentrant
(c) a reentrant function may not use the hardware in a non atomic
way
(d) a reentrant function may call any other function that are not
reentrant
answer is given as d option
a single copy of code executed by mulltiple tasks and will always
works correctly is called a reentrant code. for example , many task
may call sprintf(),but there is only a single copy of the subroutine
in the system
5)is the following code reentrant?
int j;
void f(void)
{
if(j > 10)
{
j = j+1;
printf("%d",j);
}
else
{
j = j-1;
printf("%d",j);
}
}
answer is given as no
violation of rule 1: global variable j is in a fixed loacation in
memory and therefore shared by any tasks that call f.The use of j is
not atomic, because the RTOS might switch tasks between the time it is
tested and the time that it is updated. may violate rule 2 for this
function to reentrant,printf must also be reentrant
6) In a program written in C find the major and minor cycle(rem) ?
main()
{
while(1)
{
proc_w();
proc_x();
proc_w();
proc_y();
proc_w();
proc_x();
proc_w();
proc_z();
}
}
answer is given as
major cycle wxwywxwz
minor cycle wxwz wxwy wx wy wz
if scheduling of a task is shown on time line and if the assignment
uses rate-monotonic discipline, then scheduling sequence repeats
itself after a period of time. this sequence is called a major cycle,
smaller sequence also repeat they are called minor cycles