answersLogoWhite

0


Best Answer

Assuming that the argument will only accept a structure, you must place the constant inside of a structure, and use that structure as an argument. If you're using a looser language, you may be able to get away with using a constant in the place of the structure; but either way, that's bad programming practice.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you pass a constant to a function argument that only accepts a structure?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is meant by void abcint?

void abc(int); is a function declaration. The declared function has no return value, is named abc and accepts one integer argument by value.


How structure is passed to function using structure pointer?

When you pass an object to a function you are not actually passing the object, you are only passing the object's value. This is what is meant by the term pass by value.When passing a value to a function there are actually two objects involved in the exchange: the actual argument (the object that is being passed) and the formal argument (the object used by the function). When we call a function that accepts one or more arguments (also known as parameters), the value of the actual argument is assigned to the corresponding formal argument. Thus the formal argument is a copy of the actual argument and any changes made to the formal argument will have no effect upon the actual argument.When the formal argument is a pointer, however, the value we pass is a memory address. The actual argument can either be a pointer of the same type or we can take the address of an object of the same type using the address-of operator and pass that. Either way, the value we pass is a memory address. We call this pass by reference even though the address is actually being passed by value. Passing by reference means that the formal argument and the actual argument both refer to the same object and offers an efficient means of passing large objects that are too expensive to copy. This includes most structures and unions and all arrays. Note that arrays implicitly decay to pointers and therefore cannot be passed by value. Structures and unions can be passed by value, but if they are larger than a pointer (in bytes) passing by reference is more efficient.There are four different ways to declare a formal argument as a pointer:mutable pointer to mutable typemutable pointer to constant typeconstant pointer to mutable typeconstant pointer to constant typeIdeally, functions should declare formal pointer arguments using methods 2 or 4. Both point to constant types so this gives the caller an assurance that the function has no side effects upon the object being passed by reference. Functions that use methods 1 or 3 should be regarded as having side-effects upon the object being referred to. This can be desirable for efficiency reasons, however returning values via arguments (also known as output parameters) should be avoided whenever possible.Note that it makes no difference if the formal pointer argument is mutable or constant because the formal and actual arguments are still separate objects. Constant formal arguments are only of relevance to the function designer, they are of no importance to the caller. This is true of all values passed to functions whether the value is a memory address or not. What is important to the caller of a by reference function is whether or not the object being pointed at is declared constant or not.


Why should a function that accepts an array as an argument and processes that array also accept an argument specifying the array?

Basically in c++ passing an array as an argument only provides a pointer to the first value and that function won't know how many values it has.If you read beyond the size you will just get garbage from memory.


Where to use overloading?

Default arguments are often considered to be optional arguments, however a default argument is only optional in the sense that the caller need not provide a value for it. The function must still instantiate the argument and must assign the appropriate value to it so, insofar as the function is concerned, the argument is not optional. To implement a function with a truly optional argument, we can define two overloads of that function, one that accepts the optional argument (without specifying a default value) and one that does not accept the argument. In this way we can define two different implementations, one that uses the argument and one that does not. void f (); // implementation that does not use the argument void f (int); // implementation that does use the argument In many cases, a default argument incurs no significant overhead over that of overloading. Thus we'd only use overloading to implement an optional argument where there is a significant overhead incurred by a default argument. Even so, we must also be aware that by eliminating the overhead within the function itself we may simply be passing that overhead back to the callers, because some or all of them would then have to decide which overload to call, resulting in code duplication that would likely be best handled by the function itself.


What are advantages of line structure?

It depends on what you mean by 'line structure'.

Related questions

What is meant by void abcint?

void abc(int); is a function declaration. The declared function has no return value, is named abc and accepts one integer argument by value.


How structure is passed to function using structure pointer?

When you pass an object to a function you are not actually passing the object, you are only passing the object's value. This is what is meant by the term pass by value.When passing a value to a function there are actually two objects involved in the exchange: the actual argument (the object that is being passed) and the formal argument (the object used by the function). When we call a function that accepts one or more arguments (also known as parameters), the value of the actual argument is assigned to the corresponding formal argument. Thus the formal argument is a copy of the actual argument and any changes made to the formal argument will have no effect upon the actual argument.When the formal argument is a pointer, however, the value we pass is a memory address. The actual argument can either be a pointer of the same type or we can take the address of an object of the same type using the address-of operator and pass that. Either way, the value we pass is a memory address. We call this pass by reference even though the address is actually being passed by value. Passing by reference means that the formal argument and the actual argument both refer to the same object and offers an efficient means of passing large objects that are too expensive to copy. This includes most structures and unions and all arrays. Note that arrays implicitly decay to pointers and therefore cannot be passed by value. Structures and unions can be passed by value, but if they are larger than a pointer (in bytes) passing by reference is more efficient.There are four different ways to declare a formal argument as a pointer:mutable pointer to mutable typemutable pointer to constant typeconstant pointer to mutable typeconstant pointer to constant typeIdeally, functions should declare formal pointer arguments using methods 2 or 4. Both point to constant types so this gives the caller an assurance that the function has no side effects upon the object being passed by reference. Functions that use methods 1 or 3 should be regarded as having side-effects upon the object being referred to. This can be desirable for efficiency reasons, however returning values via arguments (also known as output parameters) should be avoided whenever possible.Note that it makes no difference if the formal pointer argument is mutable or constant because the formal and actual arguments are still separate objects. Constant formal arguments are only of relevance to the function designer, they are of no importance to the caller. This is true of all values passed to functions whether the value is a memory address or not. What is important to the caller of a by reference function is whether or not the object being pointed at is declared constant or not.


When the arm is straight which structure accepts the olecranon?

the olecranon fossa


Why should a function that accepts an array as an argument and processes that array also accept an argument specifying the array?

Basically in c++ passing an array as an argument only provides a pointer to the first value and that function won't know how many values it has.If you read beyond the size you will just get garbage from memory.


Where to use overloading?

Default arguments are often considered to be optional arguments, however a default argument is only optional in the sense that the caller need not provide a value for it. The function must still instantiate the argument and must assign the appropriate value to it so, insofar as the function is concerned, the argument is not optional. To implement a function with a truly optional argument, we can define two overloads of that function, one that accepts the optional argument (without specifying a default value) and one that does not accept the argument. In this way we can define two different implementations, one that uses the argument and one that does not. void f (); // implementation that does not use the argument void f (int); // implementation that does use the argument In many cases, a default argument incurs no significant overhead over that of overloading. Thus we'd only use overloading to implement an optional argument where there is a significant overhead incurred by a default argument. Even so, we must also be aware that by eliminating the overhead within the function itself we may simply be passing that overhead back to the callers, because some or all of them would then have to decide which overload to call, resulting in code duplication that would likely be best handled by the function itself.


What are advantages of line structure?

It depends on what you mean by 'line structure'.


How do you Write a function prototype for a function named printStars that accepts no arguments and returns no data?

void printStarts (void);


What is the climax of the story marriage proposal by Anton Chekhov?

Lomov proposes and Natalya accepts with the belssing of Chubukov. Again they pick up argument


How many types of parameters passing techniques are there In c language?

There are only two methods: pass by value and pass by reference. The function itself determines how arguments are passed into the function, as defined by the function signature. If the function accepts a reference, then the argument is passed by reference, otherwise it is passed by value. Pointers are always passed by value but behave like references. The only real difference is that pointer values may be NULL but references can never be NULL.


How would you write a function prototype for a function named calcAreaReact that accepts two arguments width and length and returns the area.?

double calcAreaRect (double a, double b);


Write a function prototype named test that accepts two parameters an integer and character and returns a float?

float test(int, char);


Does a function that takes a value or values and performs an operation return a result to the caller?

Not necessarily. A function that accepts one or more arguments may process those arguments but need not return any value to the caller. In this case the function simply returns void.