What is the difference between function declaration and function definition?
// function declaration
void functionName (int, double);
// function definition
void functionName (int x, double y) {
// implementation...
}
A function declaration informs the compiler of the function's type, its name and the number and type of its arguments. A declaration is required so the compiler knows what the name represents and how it may be used, but it is not necessary to know what it does or how it does what it does.
A definition is also a declaration, but also includes the names of its formal arguments and provides the implementation details of the function itself. A declaration without a definition is not required, however declarations do help programmers to see the interface without being distracted by the implementation details. By placing declarations in a header file, multiple translation units can make use of the same declaration regardless of which translation unit defines the implementation. This also makes it possible to create functions that depend on each other because it would be impossible to define a function that used another function that hadn't yet been declared.
What is variable in c plus plus programming?
You declare a variable by first defining its data type and then its name followed by a semi-colon. Here is an example:
int variable;
The example above declares an uninitialized integer variable. You can initialize the variable by giving it a value such as "int variable = 1;". It is important to initialize your variables, because you can get errors when executing your program that the variable does not have a value or is uninitialized. Variables that are uninitialized have whatever garbage value happens to be when the program is executed.
Here are all of the data types that a variable can be:
*int - integer value
*char - character value
*bool - boolean value
What is importance of loop in c language?
importance of loops in any programming language is immense, they allow us to reduce the number of lines in a code, making our code more readable and efficient, many problems exist which cannot be solved without the looping construct. Think if you had 10000 student records, and you wanted to find the students with the highest marks, it would be difficult for you to go and check each record individually, therefore loops are used to make our task easier and efficient.
Why in copy constructor in c you use pass by reference?
Because if it's not by reference, it's by value. To do that you make a copy, and to do that you call the copy constructor. But to do that, we need to make a new value, so we call the copy constructor, and so on...
(You would have infinite recursion because "to make a copy, you need to make a copy".)
How can you use hacking in c program?
That entirely depends on what you want it to do, however it is easy to send commands to the command line using subprocess.Popen(), read files and modify them or back them up using the built in open(), or delete files.
Did this answer your question?
What is the difference between binary file and text file?
The difference is that text files may only contain printable character codes, either from the ASCII character set or the UNICODE character set. That is, letters, digits, punctuation, space, tab and other symbols, including line feed or carriage return/line feed pairs. Non-printable characters, such as the null character '\0' (or '\0\0' in UNICODE), are not permitted in plain-text files, however UNICODE files permit a 16-bit endian marker at the start of the file to denote the byte order of the wide characters that follow.
Text files can be displayed in any plain-text editor or word processor (as unformatted text). The entire text can also be extracted as a string (memory permitting), or as a stream of printable characters in a string buffer.
Binary files, on the other hand, cannot be interpreted as plain-text (although they may contain plain text elements). Binary files may contain any combination of bytes, and require special handling in order to be interpreted correctly. The exact meaning of the order of the bytes is entirely dependent upon the program that created the binary files in the first place.
The difference between Real data type and integer data type?
An integer data type is any type of number without a fractional part.
Signed vs unsigned of any data type refers to whether or not that data type can store negative numbers (numbers with a negative sign). The typical way to store the sign information for a number is to reserve one bit of information to do so.
For a signed 32-bit integer (a common integer size), this means that there are 31 bits available to hold information about the value of the number and 1 bit reserved for signifying negatives. This means that the range of data for a 32-bit signed integer is [-2147483648, 2147483647].
If you use an unsigned 32-bit integer, you can use that extra bit to store more positive number values. The range of data for a 32-bit unsigned integer is [0, 4294967295].
in short law FOR n bits
signed rang[-2n-1 -------- 2n-1 -1]
unsigned rang [0----------2n-1]
C doesn't have interfaces like Java does. In fact, it doesn't even have classes. The closes thing it has to interfaces might be a pointer to a function, which could point to one of several different functions without the caller having to know which one exactly. C does not have interfaces or classes. However it's quite easy to simulate interfaces and classes in C. Before I get into doing that, let me explain what interfaces are and how it's done in C++, which supports multiple inheritance which is much more powerful then interface inheritance.
Interface inheritance is basically the same thing as multiple inheritance. In interface inheritance, the interfaces are classes that cannot have method implementations and variables. They may only have function prototypes. You are only allowed to inherit from one full blown class as a child in the interface inheritance model.
However, in multiple inheritance (which C++ supports), you're allowed to inherit from as many full classes as you want. This allows you to make those full blown classes as slim as a bunch of pure virtual functions (interface) or as full classes with method implementations and variables. For example, to implement something similar to a comparable interface in C++:
class Comparable
{
public:
virtual int compareTo(void* x) = 0;
};
class Foobar: public Comparable
{
public:
virtual int compareTo(void* x) { /*compare implementation here */ }
//rest of class
};
That would be pretty much the same thing as interface inheritance in Java. Any function that takes a Comparable pointer or reference will also be able to take Foobar. In C, you'd have to use function pointers to achieve the same effect. Basically in your structure, you'd have to have a pseudo v-table... a bunch of function pointers:
struct Comparable
{
int (*compareTo)(void* x) = 0;
};
struct Foobar
{
int (*compareTo)(void* x);
//rest of structure
int i;
int j;
int k;
};
void InitFoobar(struct Foobar* this)
{
this->compareTo = /*compare to function*/;
//rest of the initialization
this->i = 0;
this->j = 1;
this->k = 2;
}
If you want to pass Foobar into a function that takes a Comparable pointer, just cast the Foobar pointer to a Comparable pointer. The C standard guarantees structures Comparable and Foobar will be laid out exactly the same as long as the variables are declared in the same order. So the first 4 bytes, the function pointer, will be at the exact same offsets in both Comparable and Foobar. However, after the first 4 bytes, Foobar will have extra 12 bytes of stuff where Comparable will not. This memory arrangement lets you treat Foobar exactly like a Comparable. This is also how single inheritance is normally implemented in most languages.
The main purpose of documentation is to keep records. Documentation is an integral part of all sectors of business and technology has simplified it.
Write an algorithm to find max of 10 numbers?
Someone's coursework?! This function is for an array of integers, the length of the array is Count.
int MaxInt(NumArray as *int, Count as int)
{
int Inst;
int Result;
Result = NumArray[0];
for (Inst=0;Inst
{
if(NumArray[Inst] > Result)
{
Result = NumArray[Inst];
}
}
return Result;
}
Can int value be assigned to char variable?
Yes, but the results may not be what you expect, depending on the relative sizes of an int and a char (in bytes), whether they are signed or unsigned, and whether they use big-endian notation or not.
By way of an example, in C++ an int is typically 4 bytes long while a char is 1 byte long. Both are signed by default. If you were to loop an integer from 0x80000000 to 0x7fffffff (-2147483648 to +2147483647) using big-endian notation and assign the value to a signed char, then the char would repeatedly cycle through the values 0 to 127, then -128 to 0. This is because the char takes on the value of the least-significant byte of the integer in big-endien notation (the bytes are effectively reversed in memory). However, if you cycle the int from 0xffffff80 to 0x7f (-128 to +127), then you get the expected behaviour (the char cycles from -128 to +127). However, if the char were unsigned, then the first loop would repeatedly cycle from 0 to 255 while the second would cycle from 128 to 255, and then from 0 to 127.
Thus to get the expected behaviour, both the int and char must both be signed or both must be unsigned, and the range of values must be within the range of the smaller of the two types (which will typically be the char), and the system must either use big-endian notation (reverse notation) or must otherwise compensate for little-endian notation.
A do-while loop is only useful when you want the loop to execute at least once. This is because the conditional expression is evaluated at the end of each iteration, rather than before each each iteration as it is in a for and a while loop.
Different graphics functions in'C' language?
There are no built in or standard graphics library with the original C language. The BGI library graphics.h has many functions for borland graphics. windows.h is another header file for creating user interfaces in windows.
How will you initialize a 2-d array?
All arrays are one-dimensional. A two-dimensional array is simply a one-dimensional array of one-dimensional arrays:
int a[2][3];
This is an array of 2 elements where each element is itself an array of 3 integers. In other words it is an array of 6 integers. The two dimensions simply allow us to split the array into two sub-arrays of 3 elements each.
How do you read a character from the keyboard and will store it in the variable?
Use the scanf() function from the C standard library.
What is an Program compilation?
That means to convert the original program - the source code, written by a programmer - into machine language, or into an intermediate form, for example, Java bytecode in the case of Java.
That means to convert the original program - the source code, written by a programmer - into machine language, or into an intermediate form, for example, Java bytecode in the case of Java.
That means to convert the original program - the source code, written by a programmer - into machine language, or into an intermediate form, for example, Java bytecode in the case of Java.
That means to convert the original program - the source code, written by a programmer - into machine language, or into an intermediate form, for example, Java bytecode in the case of Java.
What are the various control statement in C language?
Control statements are the statements that control the flow of program execution. For eg: loops: For, While, Do-While, decision making using if-then-else or switch-case and there's goto to transfer control.
To get output in form of nested loop?
A nested loop is just one loop within another. The most common use of this is to read from or write into a multi-dimensional array.
Example (in C-style pseudocode):
int[][] array = some collection of data
for( int i = 0; i < array.length; ++i ) { // loop through first dimension for( int j = 0; j < array[0].length; ++j ) { // loop through second dimensionprint array[i][j]} }
Is there a perfect programming language?
High-level of abstraction with low-level efficiency. Such languages already exist, but none are "perfect" in every situation. That's one of the reasons we have so many languages at our disposal. It would be impractical to combine them into a single language, you simply choose the best tool for the job at hand.
What is the 4-binary number assoiated with the hexadecimal symbol C?
0xc = 1100
Hexadecimal digits use exactly 4 binary digits (bits). The 0x0 to 0xf of hexadecimal map to 0000 to 1111 of binary. Thinking of the hexadecimal digits as decimal numbers, ie 0x0 to 0x9 are 0 to 9 and 0xa to 0xf are 10 to 15, helps with the conversion to binary: 0xc is 12 decimal which is 8 + 4 → 1100 in [4 bit] binary.
What is java primitive data types?
Any data that is not stored as an object - like the integral data types (int, long, etc.), or boolean variables.
Any data that is not stored as an object - like the integral data types (int, long, etc.), or boolean variables.
Any data that is not stored as an object - like the integral data types (int, long, etc.), or boolean variables.
Any data that is not stored as an object - like the integral data types (int, long, etc.), or boolean variables.
Algorithm to find factorial using functions?
factorial using recursion style in c++ is
unsigned int fact(unsigned int a)
{
if (a<=1)
return 1;
else
{
f*=fact(a-1);
return a;
}
}
when using looping structure factorial is
unsigned int fact (unsigned int n)
{
unsigned int i,f=1;
for(i=1;i<=n;i++)
f*=i ;
return f;
}