Solved

c programming

Posted on 2000-03-10
6
150 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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…

838 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