473,799 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C questions

Dear all,

I was going through a C book written by an indian author
the following are the questions given in that book

1) consider the following statement:
s1 : an operator may require an lvalue operand, yet yield an r
value
s2: an operator may accept an rvalue operand , yet gives an lvalue

which of the following is true about s1 and s2

(a) both s1 and s2 are true
(b) only s1 correct
(c) only s2 is correct
(d) both are false

answer is given as (a)

& is one such operator
int n;
*n is lvalue
&n is rvalue

operator operand result
& n is l value &n rvalue

* (p + 1) is r value *(p + 1) lvalue
2) which of the following is false

a) a string has type array of characters
b) a string has storage class static
c) adjacent string literals are concatenated into a single string
d) Concatenation of ordinary and wide string literal is a single
string

answer is given as d option

3)consider the following

process1(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 == 1

answer is given as a option

4) consider the following statements

s1: 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

which of the following is true
(a) only s1
(b) both are correct
(c) only s2 is correct
(d) both are wrong

answer is given as b option

5)which operation require more memory access
(a) branch
(b) conditional code test
(c) shift register right /* what is this ?*/
(d) all are same

answer is given as d option

well what do you folks think of all this stuff ?
Jan 7 '08
23 2771
On Jan 7, 10:07 pm, Harald van D©¦k <true...@gmail. comwrote:
On Mon, 07 Jan 2008 08:50:08 -0800, sophia.agnes wrote:
2) which of the following is false
4) consider the following statements
s1: 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

I don't understand these statements. When x is an object, *&x is
completely equivalent to x, and when x is a pointer, &*x is equivalent to
x, except that it is not an lvalue.
This is what you meant is n't it ?

#include<stdio. h>
#include<stdlib .h>
#include<string .h>

int main(void)
{

int *x,n=10;
x = &n;

if( &*x == x)
puts("EQUAL");
else
puts("NOT EQUAL");

printf("\n *x = %p",*x);
printf("\n &n = %p",&n);

return(EXIT_SUC CESS);
}

I am getting output as
EQUAL

*x = 0xa
&n = 0xbf84e8a0

now can you make it clear that why &*x isn't a l value ?
is it because we can't assign to it or any other reason ?
Jan 8 '08 #21
On Mon, 07 Jan 2008 22:48:19 -0800, sophia.agnes wrote:
now can you make it clear that why &*x isn't a l value ? is it because
we can't assign to it or any other reason ?
It's the other way around: we can't assign to it because it isn't an
lvalue. It's an expression that is not directly formed by reading an
object. It's the same way that x+0 isn't an lvalue, even though for most
arithmetic types, it's otherwise completely equivalent.

What would you expect & &*x to mean? Would you want it to give you a
pointer to x? If you would, then where do you stop? Consider x+0 again,
would you consider that an lvalue? And if so, how about when x is of type
short (so x+0 is of type int)? I'm not saying it couldn't be done, but
getting all the details right would be far more trouble than it's worth.
Jan 8 '08 #22
ri*****@cogsci. ed.ac.uk (Richard Tobin) writes:
In article <88************ *************** ***@bt.com>,
Richard Heathfield <rj*@see.sig.in validwrote:
[...]
>>& can take the name of a function, which is far from being an lvalue!

Though you are of course right about that, the answer does come close
to the *idea* of lvalues. The idea of an lvalue is that it's
something on the left-hand side of an assignment - something that can
be assigned to - a place rather than a value. The ability to take the
address of something clearly implies that it is a place.

The fact that you can't say

int foo(void) {...}
int bar(void) {...}
...
foo = bar;

is not really any different from the situation with

int foo[10];
int bar[10];
...
foo = bar;

so there's no real reason why function names should not be considered
lvalues just as array names are.
There is a real reason: an lvalue designates an object, and a function
is not an object. Whether that's a real *good* reason is another
question.

--
Keith Thompson (The_Other_Keit h) <ks***@mib.or g>
[...]
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jan 8 '08 #23
Ravishankar S wrote:
<so**********@g mail.comwrote in message
news:3e******** *************** ***********@n22 g2000prh.google groups.com...
>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
That doesn't qualify, because "==" does not require an lvalue operand.

On the other hand, "=" does require an lvalue operand, and I've already
given a=3 as ane example.
>4) consider the following statements

s1: evaluating the address of an object value after indirection is
simply object

>s2:evaluatin g 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 ??
No, equality applies to values. The clearest way to show that an
expression refers to an object is to use the expression to assign a
value to the object it refers to, though this only applies to modifiable
lvalues. As far as I can tell what he's saying is that:

int i, *p;

// s1: Take address after performing indirection.
// Since &(*p) supposedly refers to an object, this
// should not be a constraint violation:
&(*p) = &i;

// s2: Perform indirection after taking address
// Since *(&i) supposedly does not refer to an object,
// this should be a constraint violation:
*(&i) = 3;
>which of the following is true
(a) only s1
(b) both are correct
(c) only s2 is correct
(d) both are wrong

answer is given as b option
If I'm correct about what the author meant, he's got it exactly backwards.
Jan 8 '08 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4107
by: softwareengineer2006 | last post by:
All Interview Questions And Answers 10000 Interview Questions And Answers(C,C++,JAVA,DOTNET,Oracle,SAP) I have listed over 10000 interview questions asked in interview/placement test papers for all companies between year 2000-2005 in my website http://www.geocities.com/allinterviewquestion/ So please have a look and make use of it.
0
4602
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
2
7229
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
4
2514
by: Drew | last post by:
I posted this to the asp.db group, but it doesn't look like there is much activity on there, also I noticed that there are a bunch of posts on here pertaining to database and asp. Sorry for cross-posting. I am trying to build a "checklist", where a user can navigate to an ASP page on the intranet which shows a list of "questions" that the user can check off. I am trying to figure out how to do this so that it is scalable, but I am...
8
7988
by: Krypto | last post by:
Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying to catch up again with Python. I am now appearing for Job Interviews these days and I am wondering if anybody of you appeared for a Python Interview. Can you please share the questions you were asked. That will be great help to me.
0
1504
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers7.html C# Interview Questions and Answers 6 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers-6.html C# Interview Questions and Answers 5...
1
1626
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers7.html C# Interview Questions and Answers 6 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers-6.html C# Interview Questions and Answers 5...
0
4517
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers7.html C# Interview Questions and Answers 6 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers-6.html C# Interview Questions and Answers 5...
0
3434
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions http://interviewdoor.com/technical/C-Interview-Questions.htm C# Interview Questions http://interviewdoor.com/technical/C-sharp-Interview-Questions.htm C++ Interview Questions http://interviewdoor.com/technical/C++-Interview-Questions.htm
0
2946
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions http://interviewdoor.com/technical/C-Interview-Questions.htm C# Interview Questions http://interviewdoor.com/technical/C-sharp-Interview-Questions.htm C++ Interview Questions http://interviewdoor.com/technical/C++-Interview-Questions.htm
0
9546
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10491
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10268
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9079
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5593
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.