473,513 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Few Queries Please do answer

16 New Member
Few Queries:

1. Difference between parameters and arguments while calling a function?
2. Difference between memcpy() and memset()?
3. Difference between memcmp() and strcmp()?
4. What happens in this code:
main()
{
char arr[3];
arr[0]=0;
arr[1]='0';
printf("%s,%s,%s",&arr[0],&arr[1],&arr[3],&arr[2]);
}

Please help me
Oct 18 '07 #1
6 1456
Meetee
931 Recognized Expert Moderator Contributor
Hi,

These topics are easily available and explained in various sites. You can search on google by pasting the same lines there. Also run the program and see the output :)

Regards
Oct 18 '07 #2
bindiya182003
16 New Member
Hi,

These topics are easily available and explained in various sites. You can search on google by pasting the same lines there. Also run the program and see the output :)

Regards
I know that from google I will get answers for these question. Since I didn't get a satisfying answers I asked in this site.And I got every good answer from this site people.Thanks a lot for your help.Other questions answers also I will get from google then whats the use of this site.Then regarding the output i wanted an explanation. Really sad to get such a reply.And sorry for disturbing you people.
Oct 18 '07 #3
Meetee
931 Recognized Expert Moderator Contributor
I know that from google I will get answers for these question. Since I didn't get a satisfying answers I asked in this site.And I got every good answer from this site people.Thanks a lot for your help.Other questions answers also I will get from google then whats the use of this site.Then regarding the output i wanted an explanation. Really sad to get such a reply.And sorry for disturbing you people.
That is why you should read posting guidelines. Whatever you wrote in your second post, you should write it in your first post. Then reader can understand that you have taken efforts, as we are not allowed to spoonfeed and self work is the best help. That's why I wrote such answer to work by yourself as I was not known that you have worked so far.

Anyways,
Your first answer is :

When a function is defined, the expected variables are listed in parentheses. These are parameters.

For example:
Expand|Select|Wrap|Line Numbers
  1. void fun(length)
  2. {
  3. .....
  4. }
here length is a parameter of the Square function.

When a function is called, there is a list of variables that are passed to the function. These are arguments. Like:

Expand|Select|Wrap|Line Numbers
  1. int length = fun(length);
  2.  
For memset and memcpy you can refer http://www.cplusplus.com/reference/c...ng/memset.html (Thanks to Google search)

Difference between memcmp and strcmp is:strcmp() compares characters up until it sees the first '\0' in either string. As soon as character difference is found or '\0' is found it returns while memcmp() does not look for '\0'. It looks for the first difference considering the size specified.

For that output experts may help!!

Regards
Oct 18 '07 #4
bindiya182003
16 New Member
That is why you should read posting guidelines. Whatever you wrote in your second post, you should write it in your first post. Then reader can understand that you have taken efforts, as we are not allowed to spoonfeed and self work is the best help. That's why I wrote such answer to work by yourself as I was not known that you have worked so far.

Anyways,
Your first answer is :

When a function is defined, the expected variables are listed in parentheses. These are parameters.

For example:
Expand|Select|Wrap|Line Numbers
  1. void fun(length)
  2. {
  3. .....
  4. }
here length is a parameter of the Square function.

When a function is called, there is a list of variables that are passed to the function. These are arguments. Like:

Expand|Select|Wrap|Line Numbers
  1. int length = fun(length);
  2.  
For memset and memcpy you can refer http://www.cplusplus.com/reference/c...ng/memset.html (Thanks to Google search)

Difference between memcmp and strcmp is:strcmp() compares characters up until it sees the first '\0' in either string. As soon as character difference is found or '\0' is found it returns while memcmp() does not look for '\0'. It looks for the first difference considering the size specified.

For that output experts may help!!

Regards
Thanks a lot for your reply...Because I was in a hurry i was not able to post the details....And I was really in need of these things in my office work...

Anywayz thanks for your help..Sorry for getting rude.
Oct 18 '07 #5
Banfa
9,065 Recognized Expert Moderator Expert
4. What happens in this code:
Expand|Select|Wrap|Line Numbers
  1.     main()
  2.     {
  3.      char arr[3];
  4.      arr[0]=0;
  5.      arr[1]='0';
  6.      printf("%s,%s,%s",&arr[0],&arr[1],&arr[3],&arr[2]);
  7.      }
  8.  
This program invokes undefined behaviour on at least 2 counts and probably 4. The output could therefore be anything. Undefined behaviour is bad, as soon as it is invoked the compiler/program is free to do anything it chooses.

Here is a list of the problems causing undefined behaviour
  • main MUST return int.
  • &arr[3] is an out of bounds array access.
  • &arr[1] and &arr[2]. At compile time these are not specifically undefined behaviour. However you have told printf they are pointers to strings, it will keep printing the characters until it finds a '\0' character. Unless arr[2] == '/0' this means it will access memory outside the bounds of the array. Since arr is on the stack it is not initialised and arr[2] is never set so it will be unlikely to have the value '\0'. This means that both these expressions will probably cause an out of bounds array access which, as above invokes undefined behaviour.
Oct 18 '07 #6
weaknessforcats
9,208 Recognized Expert Moderator Expert
1. Difference between parameters and arguments while calling a function?
A parameter is the value of the argument.

For functions you have arguments. When you call the function you provide the parameter.

The same applies to templates. Templates have arguments for the type. When you supply the types at compile time, you parameterize the template. That's why templates are called parameterized types.
Oct 18 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1247
by: Jean-Paul | last post by:
Hi, This "query2" is used in an MS Access environment. SELECT T_Perso.*, query1.* FROM T_Perso LEFT JOIN query1 ON T_Perso.IdPerso = query1.IdPerso; In SQL, "query1" is :
5
3704
by: WertmanTheMad | last post by:
Ive been playing with this for a few days and thought I might thow it out for seggestions. I have Several Queries that need counts returned The Queries are Mutually Exclusive meaning whatever...
2
367
by: Freeserve | last post by:
Not sure whether this is the right group, but I can't find anything in the ..NET groups and my apologies if this has already been covered or is considered "off subject". I am looking at using an...
5
4004
by: Jerry Hull | last post by:
I'm working with a database developed by an untrained person over several years - and on a network that has recently been upgraded with a new server installed and MS office upgraded from 2K (I...
2
2004
by: vulcaned | last post by:
I'm thinking I might want to move the back-end to one of my Access97 applications to SQLServer instead of continuing to use Access jet but before I start/do that I have several questions I'm hoping...
9
1694
by: Jay | last post by:
ok have this program and i set a socket 2 connect to the server...so i can chat on the channels and stuff. my question is how would i go about set a socket directly 2 an individual query? my...
5
10618
by: HS Hartkamp | last post by:
Hi all, I am working with fairly large databases (> 500 Mb / < 2,000,000 rexcords), and often need to do action queries on these. I have the feeling that much of the computing power is going...
7
1946
by: Henrootje | last post by:
I have to run a lot of append queries. I have data in tables in old databases that has to be appended to tables in a new database. I made a new database in which I linked the old tables and the...
4
3161
by: David Wright | last post by:
Hello Folks I have a Macro which consecutively opens seven ‘Make Table Query’s’. Each query requests two parameter inputs i.e. ‘Please Enter Department Code’ and ‘Please Enter Year’. It is...
0
7160
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...
0
7384
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,...
0
7537
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...
0
7525
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...
1
5086
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...
0
4746
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...
0
3233
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...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.