473,609 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

some tricky questions

1) void foo(char *s,char *t)
{
while(*s++=*t++ );
}

which C function is equivalent to foo ?

2) #define ROUND(x,n)

((x+n-1)&(~(n-1)))
what is hte value of ROUND(223,64) ?
DESCRIBE IT HOW IT IS SO?

3) void foo(int x)
{
int i=0;
while(x)
{
x=x&(x-1);
i++;
}
printf("%d",i);
}
what is the o/p of this function & why it is so ?
what function does this '&' does ?
4) union{
int i;
char c[sizeof(int)];
}x;
x.i=1;
if(x.c[0]==1)
printf("the m/c is _______________ endian");
else
printf("the m/c is _______________ endian");

fill in the blanks with tthe correct option:
a) little,big b)big,big
c) big,little d)little,little

5) int fun2(char *a,char *b)
{
for(; *a==*b;a++,b++)
if(*a=='\0')
return 0;

return *a-*b;
}
char a[10]="date",b[10]="data";

what is the value of fun2(a,b)?

Jun 2 '07 #1
28 13586
bi**********@gm ail.com wrote:
1) void foo(char *s,char *t)
{
while(*s++=*t++ );
}

which C function is equivalent to foo ?
FYI, we don't do homework.

--
Tor <torust [at] online [dot] no>
Jun 2 '07 #2

<bi**********@g mail.comha scritto nel messaggio
news:11******** **************@ n15g2000prd.goo glegroups.com.. .
1) void foo(char *s,char *t)
{
while(*s++=*t++ );
}

which C function is equivalent to foo ?
None. strcpy returns a char* equal to its first argument. Also, the
second argument of strcpy is a const char*.
2) #define ROUND(x,n)

((x+n-1)&(~(n-1)))
what is hte value of ROUND(223,64) ?
DESCRIBE IT HOW IT IS SO?
It is the value of ((223+64-1)&(~(64-1))), of course.
3) void foo(int x)
{
int i=0;
while(x)
{
x=x&(x-1);
i++;
}
printf("%d",i);
}
what is the o/p of this function & why it is so ?
what function does this '&' does ?
If x is INT_MIN, it is allowed to make demons fly out of your nose.
BTW, what is an o/p? And the '&' does no "function", at least in the C
sense.
4) union{
int i;
char c[sizeof(int)];
}x;
x.i=1;
if(x.c[0]==1)
printf("the m/c is _______________ endian");
else
printf("the m/c is _______________ endian");

fill in the blanks with tthe correct option:
a) little,big b)big,big
c) big,little d)little,little
Nope. It could be middle endian. And if I'm not wrong, the standard
specifies nothing about the bit order. On a conforming implementation, it
could be sizeof (int) == 2 && CHAR_BIT ==8, and
the first byte of i could contain the first, third, fifth, seventh,
ninth, eleventh, thirteenth, and fifteenth bit in that order, and
the second byte could contain the sixteenth, fourteenth, ..., second bit in
that order.
5) int fun2(char *a,char *b)
{
for(; *a==*b;a++,b++)
if(*a=='\0')
return 0;

return *a-*b;
}
char a[10]="date",b[10]="data";

what is the value of fun2(a,b)?
It is 'e' - 'a', which nothing requires to be four. It could be
anything from CHAR_MIN - CHAR_MAX to -1 included, and it could be
anything from 1 to CHAR_MAX - CHAR_MIN included. Not all the world
uses ASCII.
Jun 2 '07 #3
On Jun 2, 12:28 pm, "Army1987" <please....@for .itwrote:
<birensubu...@g mail.comha scritto nel messaggionews:1 1************** ********@n15g20 00prd.googlegro ups.com...

[...]
2) #define ROUND(x,n)
((x+n-1)&(~(n-1)))
what is hte value of ROUND(223,64) ?
DESCRIBE IT HOW IT IS SO?

It is the value of ((223+64-1)&(~(64-1))), of course.
[...]
The reason: "by definition".
[:)]-|--<

/Per

--

Per Erik Strandberg
home: www.pererikstrandberg.se
work: www.incf.org
also: www.spongswedencare.se

Jun 2 '07 #4
In article <11************ **********@n15g 2000prd.googleg roups.com>,
<bi**********@g mail.comwrote:
>1) void foo(char *s,char *t)
{
while(*s++=*t++ );
}

which C function is equivalent to foo ?
What is homework, Alex?

Jun 2 '07 #5
bi**********@gm ail.com writes:
1) void foo(char *s,char *t)
{
while(*s++=*t++ );
}

which C function is equivalent to foo ?
foo.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 2 '07 #6
On Jun 2, 6:28 am, "Army1987" <please....@for .itwrote:
<birensubu...@g mail.comha scritto nel messaggionews:1 1************** ********@n15g20 00prd.googlegro ups.com...
1) void foo(char *s,char *t)
{
while(*s++=*t++ );
}
which C function is equivalent to foo ?

None. strcpy returns a char* equal to its first argument. Also, the
second argument of strcpy is a const char*.
2) #define ROUND(x,n)
((x+n-1)&(~(n-1)))
what is hte value of ROUND(223,64) ?
DESCRIBE IT HOW IT IS SO?

It is the value of ((223+64-1)&(~(64-1))), of course.
3) void foo(int x)
{
int i=0;
while(x)
{
x=x&(x-1);
i++;
}
printf("%d",i);
}
what is the o/p of this function & why it is so ?
what function does this '&' does ?

If x is INT_MIN, it is allowed to make demons fly out of your nose.
BTW, what is an o/p? And the '&' does no "function", at least in the C
sense.
4) union{
int i;
char c[sizeof(int)];
}x;
x.i=1;
if(x.c[0]==1)
printf("the m/c is _______________ endian");
else
printf("the m/c is _______________ endian");
fill in the blanks with tthe correct option:
a) little,big b)big,big
c) big,little d)little,little

Nope. It could be middle endian.
Right.
And if I'm not wrong, the standard
specifies nothing about the bit order. On a conforming implementation, it
could be sizeof (int) == 2 && CHAR_BIT ==8, and
the first byte of i could contain the first, third, fifth, seventh,
ninth, eleventh, thirteenth, and fifteenth bit in that order, and
the second byte could contain the sixteenth, fourteenth, ..., second bit in
that order.
Thankfully you are wrong about this, see 9899:1999 section 6.2.6.2.

Robert Gamble

Jun 2 '07 #7
Tor Rustad <to********@hot mail.comwrites:
bi**********@gm ail.com wrote:
>1) void foo(char *s,char *t)
{
while(*s++=*t++ );
}

which C function is equivalent to foo ?

FYI, we don't do homework.
Who is "we"? Because someone else did.
Jun 2 '07 #8
On Sun, 03 Jun 2007 00:12:06 +0200, in comp.lang.c , Richard
<rg****@gmail.c omwrote:
>Tor Rustad <to********@hot mail.comwrites:
>bi**********@gm ail.com wrote:
>>1) void foo(char *s,char *t)
{
while(*s++=*t++ );
}

which C function is equivalent to foo ?

FYI, we don't do homework.

Who is "we"? Because someone else did.
Did'ja read the answers? Not entirely likely to pass the homework
test...

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Jun 2 '07 #9
Richard wrote:
Tor Rustad <to********@hot mail.comwrites:
[...]
>FYI, we don't do homework.

Who is "we"? Because someone else did.
I exclude spammers, and that someone else was spamming in my view.
--
Tor <torust [at] online [dot] no>
Jun 3 '07 #10

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

Similar topics

2
2249
by: Daniel | last post by:
I'm a newcomer to .Net and am slowly becoming familiar with it, so I have some simple questions. Here's the situation: I created a VB.Net project for my data access layer (DAL), another VB.Net project for my business logic layer (BLL), and am using ASP.Net web forms as the front end. So I want by BLL to reference the DAL and the ASP.Net project to reference the BLL. Questions:
2
3203
by: Kennedy_f | last post by:
Most questions of exam 70-228 have a selection of answers that all seem correct, but in reality, the right answer is the one that best solves the question.There a few trick questions like how to allow someone access to SQL Server using the Guest account over the Internet, and i solved such type of tricky questions before in ucertify. I feel i could have done better. Good luck to all who are preparing to take this exam.
1
7470
by: asdsd sir | last post by:
Hi!I'm new in Python and i'd like to ask some general questions about stdin,stdout... Firstly... if we type like something like : cat "file.txt"|python somefile.py #somefile.py import sys
2
1509
by: Water Cooler v2 | last post by:
I've not touched SQL server programming since 1999. I have very little memory of it and need some clarifications on some basic questions that I could even use a book for. Until I get myself a good book, someone please help me with the answers: 1) What are SQL functions and how are they different from stored procedures? Do both of the programming objects not achieve the same thing? What was the need of having one in addition to the...
0
8579
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
8555
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...
1
8232
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8408
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7024
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
6064
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
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4098
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1686
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.