Solved

c programming

Posted on 2000-03-10
6
148 Views
Last Modified: 2010-04-02
please explain with examples call by value and call by pointers?
explain how the pointers arithmatics takes place.Alloc.h and type.h
have what functions?
0
Comment
Question by:mohua_banerjee
  • 3
  • 2
6 Comments
 

Author Comment

by:mohua_banerjee
ID: 2604743
thank  you for your cooperation
0
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 2604818
in call by value you pass a copy of a value to a function, like

void F(int i) // i is a copy of a value passed.
{
   i = 5; // changes copy of value passed.
}

int main()
{
   int x = 1;
   F(x);  // does not change x.
}

In call by reference, a reference or pointer to the specified value is passed This reference may be used to change the actual value that was specified

void F(int *iptr) // Pointer to an int is passed.
{
   *i = 5; // changes value of caller's int.
}

int main()
{
   int x = 1;
   F(&x);  // Changes x.
}
0
 

Author Comment

by:mohua_banerjee
ID: 2605426
sir,i have not got all thE answer.if possible,please answer others.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:nietod
ID: 2605481
I don't know what

>> explain how the pointers arithmatics takes
>> place.Alloc.h and type.h
>> have what functions?

means.  It doesn't make sense.

Also EE rules do state that you should only ask 1 question per EE question.   They also recommend a 50 point value for an easy question, 20 points for 2 questions is too little. I will answer the 2nd question--if you can explain it, but in the future try to ask only 1 question at a time and assign them fair point values.
0
 
LVL 3

Expert Comment

by:Iexpert
ID: 2606493
I haven't a clue what you mean in the 2nd part of the question.

A note on pinter arithmetic though,
is that you can subtract pointers to
find out how much space between them
e.g:

char *p1, *p2;
p1 = "My String"
p2 = p1 + 3;

//p2 - p1 == 3
//p1 = "My String"
//p2 = "String"

//Because p1 is a pointer to char
//the following moves the address of
//p1 up 3 chars (bytes)
p1+=3;

//NB The above operation is dependent
//on type. Therefore:
int* p3;
int test[]={1,2,3,4};
p3 = &test;

//The following makes *p3 == 2
//even though an int take up 2 bytes
//memory. The compiler works this out
//automatically for you
p3++;

As for alloc.h, these functions
are for dynamically creating memory
on the heap.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2608200
mohua_banerjee,
   You offered a very low point value for this question, then when I answered it, you gave me a bad grade too!  You should only give a low grade if the answer is incorrect.  My answer was not incorrect.  If you don't understand the answer you can ask for clarification, but to simply grade a question with a low grade for no reason is not fair.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now