answersLogoWhite

0


Best Answer

Functions are declared by specifying the function return type (which includes any use of the const qualifier), the name of the function, and the function's argument types enclosed in parentheses (round brackets), which also includes any use of the const qualifier. The declaration ends with a semi-colon. Arguments may also be given default values but if any argument has a default value, all arguments that follow must also have default values.

[const] type name([[const] type [=value][, ...]]);

Declarations may also contain definitions in which case you must include the formal argument names that will be used by the definition. The definition (or implementation) must be enclosed in braces (curly brackets) and the semi-colon must be omitted.

[const] type name([[const] type arg1 [=value][, ...]])

{

statement;

}

Functions must be declared before they can be used. In most cases it is necessary to forward declare functions in a header. In these cases, default values must be omitted from the definition.

Functions that do not return a value must return void. Functions that do not accept arguments must still include the argument parentheses. Use of the void keyword to indicate no arguments is optional. Thus the following declarations are exactly the same (although declaring both in the same program would be invalid):

void f();

void f(void);

As well as the return type and argument types, class member functions (methods) can also be modified with the const qualifier:

struct obj

{

void f(void) const;

};

The const keyword assures the caller that the object's immutable members will not be modified by the function (that is, the internal state of the object's immutable data will remain unaltered). Also, when working with constant objects, only constant methods can be called.

Functions can also be declared static. In the case of external functions, the static keyword limits the visibility of the function to its translation unit. In the case of class methods, static member functions are local to the class as opposed to instances of the class. Static member functions do not have access to an implicit this pointer since they are not associated with any instance of the class but are accessible even when no instances of the class exist.

User Avatar

Wiki User

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

Wiki User

13y ago

You cannot call any C++ function/method from C

(but the other way perfectly legal: you can call C from C++)

C++ contains as a subset the C language (almost entirely). I is there fore possible to write a C program to use public member functions <if they are static methods!>, all you do is compile with a C++ compiler.

C++ is picky about type casting, you have to be explicit where with C it is automatic.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

No. It has built-in types and operators, but no built-in functions. Functions must be user-defined, but you may include functions from third-party libraries as well as from the standard library.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How function declared in C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Where is the global declaration section of a c plus plus program?

Anything declared outside of a function is global.


What are the building function in c plus plus?

There is no such term as "building function" in C++.


A c plus plus statement that invokes a function is known as?

...a function call.


When will you make a function inline in c plus plus?

yes,we can make function inline


What is the only function all C plus plus programs must contain?

Every C plus plus program that is a main program must have the function 'main'.


In C plus plus when a function is executing what happens when the end of the function is reached?

Control is returning to the caller of the function.


What do you call an object function in c plus plus?

method


What is a main function in c plus plus?

It is the first function that gets called when the program is executed.


What is rand function in c plus plus?

The rand() function returns an integer (int) value that represents a pseudo-random number between 0 and RAND_MAX, RAND_MAX being a constant declared in the run-time library. Each time rand() is invoked, a different value is returned.


What is the function y equals ax2 plus bx plus c?

It is a quadratic function which represents a parabola.


How do you create folder with c plus plus?

Use function mkdir.


Why to use gotoxy function in c plus plus?

to locate coordinates ..