answersLogoWhite

0


Best Answer

## posted BY Pulkit ok. so to declare variable argements in arguments use this: ret_type function_name( . . .); using these three dots will tell compiler to include variable aarguments. Note: this feature has been included in New version of C,, this is not available in old compiler. thankx guys n grls ## posted BY Pulkit ok. so to declare variable argements in arguments use this: ret_type function_name( . . .); using these three dots will tell compiler to include variable aarguments. Note: this feature has been included in New version of C,, this is not available in old compiler. thankx guys n grls

User Avatar

Wiki User

16y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

By reference or by pointer, never by value. Passing by value would require the string to be copied, which is detrimental to performance. If the reference or pointer is constant, no changes will be made to the string, so its safe to pass a reference or pointer. If it is non-constant, this implies the string will be altered, so if you do not want the original string altered, you must copy the string and pass a reference or pointer to the copy instead. Some functions may provide a pass by value overload to cater for this, but that's an exception rather than a rule.

Remember that strings are nothing more than arrays of char (or wide char if using UNICODE), so they can be passed to functions just as you would any other type of array. When passing pointers, however, be sure the string is null-terminated, otherwise you must pass the string's length as well to avoid a buffer overrun.

Functions that operate on strings often provide several overloads to cater for all the different ways you might pass string, both with and without a buffer length. When creating user-defined functions that accept strings, this isn't really necessary, so long as you pass strings to those functions in a consistent way. However, if your functions will be distributed to third-parties, its best to provide fully-overloaded methods.

Generally, a string pointer is passed to a function as const char * (constant pointer) or just char * (non-constant pointer). However, you may have access to other typedefs for a string, including object references such as CString, or string templates such as CStringT. Regardless, they all boil down to an array of characters.

This answer is:
User Avatar

User Avatar

Wiki User

9y ago

You pass parameters (or arguments) to the main function via command-line switches.

int main (int argc, char* argv[]) {

/* ... */

return 0;

}

The argv argument is a null-terminated array of null-terminated strings while argc holds the count of strings. The argc argument is always at least 1 because the first argument (argv[0]) is always the program name while argv[argc] is always null.

If your program is called my_prog.exe, then you can pass arguments to it from the command line like so:

my_prog arg1 arg2 arg3

Note that whitespace separates each argument.

Your main function will then hold the following values:

argc = 4

argv[0] = "<path>\my_prog.exe"

argv[1] = "arg1"

argv[2] = "arg2"

argv[3] = "arg3"

argv[4] = null

As programmer, it is your job to parse the command line and check for input errors before processing the switches and taking the appropriate action(s).

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

operating systme call the main function in c

execution start from main and ends with main

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can you pass variable arguments to a function in c?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How will you pass arguments to a function in c plus plus?

If you have this function: int add(int x, int y) { return x + y; } you would pass the arguments when calling the function in the () like this: add(4, 7); 4 &amp; 7 would be the arguments.


How do you pass enum object as argument to function in c?

You can't pass an enum as an argument to a function. An enum in C isn't an object, it's a type. All you can do is pass a variable that is of the particular enum's type.


Why you pass arguments to function in c plus plus?

You pass arguments to functions because that is how you tell the function what you want it to do. If you had, for instance, a function that calculated the square root of something, you would pass that something as an argument, such as a = sqrt (b). In this case sqrt is the function name, b is passed as its argument, and the return value is assigned to a.


What is meant by arguments in c?

Arguments appear in functions and in function calls. Arguments passed to a function are known as actual arguments. The arguments used by the function are known as the formal arguments. In C, all arguments are passed by value, such that the formal argument is a copy of the actual argument.


How can called function determine number of arguments that have been passed to it in C language?

use the variable length argument - va_arg va_list ca_start and va_end macros


How do you pass command line arguments using turbo in c compiler?

In the Options menu the Arguments command.


What is calling by reference how it is different from call by value in c program?

Calling a function by value means the variable will be copied. That means that, any changes you make to the variable will be applied to the copy, and not the real one. If you pass by reference, the actual intended variable is modified.


When calling a function that has multiple parameters can you list the arguments in any order?

No. C function argument are positional.


Does C even have pass by reference?

Strictly speaking, no. All arguments in C are passed by value. However, when the argument being passed is a memory address, although the address itself is passed by value, we're effectively passing the object that resides at that address -- by reference. Thus when a function's formal argument is a pointer variable (of any type), then it can be taken as read that the function is using the pass by reference semantic rather than the pass by value semantic. Nevertheless, it is important to keep in mind that the formal argument is assigned a copy of the actual argument and is therefore being passed by value.


Write a c program for function with no arguments and no return values?

void mynullfunction () {;}


What is a basic structure of a c programming?

Basic structure of a C program is /* Documentation section */ /* Link section */ /* Definition section */ /* Global declaretion section */ /* Function section */ (return type) (function name) (arguments...) void main() { Declaration part Executable part (statements) } /* Sub-program section */ (return type) (function name 1) (arguments...) (return type) (function name 2) (arguments...) . . . (return type) (function name n) (arguments...) Basic structure of a C program is /* Documentation section */ /* Link section */ /* Definition section */ /* Global declaretion section */ /* Function section */ (return type) (function name) (arguments...) void main() { Declaration part Executable part (statements) } /* Sub-program section */ (return type) (function name 1) (arguments...) (return type) (function name 2) (arguments...) . . . (return type) (function name n) (arguments...)


Which header file is used to develop a function that can accept variable number of arguments?

.If you want to accept variable no of arguments then you have to include which of the following header files a) Vararg.h b) stdarg.h c) stdlib.h d) stdioh