When does a function need an include directive?
A function requires an include directive whenever it makes use of a data type or function that cannot be forward declared, or where a forward declaration would be undesirable, and where a complete declaration of that type or function exists in another file.
That may sound far more complex than intended, but it's really quite simple. The include directive is a signal to the compiler that the specified file is to be inserted into your file in its entirety, just as if you'd typed all the code it contains by hand. This is clearly a huge time saver when it comes to common data types and functions, but how do you decide if an include directive is actually required or not? Simple: comment out the directive and attempt to compile. If it fails, the directive is required. The errors raised will indicate exactly what types or functions it exposes and where they are used.
Most C/C++ programmers split their declarations from their definitions. Declarations of functions and data types (including class declarations) are usually placed in a header file (.h), while the definitions of the functions are safely tucked away in a separate source file (.cpp). Programmers are rarely interested in the implementations -- the header should contain all the information necessary to make use of the functions and data types contained therein. But in order to compile, the source file must include the header file. And if the two files must include other files, then we generally place those directives in the header file thus ensuring that the header contains all the necessary information to allow it to be included in other files.
What is the command prompt that directs output from a program to a file?
You have to include one more file:
#include <fstream.h>
//Which is responsible for operations with files
//Then call a variable of stream type
main ()
{
ofstream out_stream;
//And use out_stream like you use cout
int data_X;
...
data_X >> out_stream;
...
}
Can you run java program in turbo c or c plus plus?
Turbo C++ pre-dates the earliest C++ standard, ISO/IEC 14882:1998 (informally known as C++98). As such it is impossible to write standards-conforming C++ programs in Turbo C++. In particular, it lacks template metaprogramming and exception handling both of which are central to C++., and there is no standard template library because it didn't exist at the time. It's also 16-bit which limits its memory usage to 64KB, although DPMI can extend that limit to some degree.
Development of Turbo C++ effectively ceased in 1994. It was later revived in 2006 with two separate releases, Explorer (the free version) and Professional, but none of its inherent problems were resolved and no further development took place. Embarcadero acquired the software from Borland in 2008 and support was discontinued in 2009.
Today, the free version of Turbo C++ still finds uses in educational institutes (primarily in Asia) despite the fact it's of no practical use in learning C++ let alone writing C++ programs.
Turbo C++ was succeeded by C++ Builder. The current stable release is v10.1 Berlin, released in 2016.
How does the Java programming language work?
Java uses a code-compiler, which does not create a machine-code, like normal Windows programs, but a byte-code, which the Java interpreter runs. It is like a mini-operating system, forming a layer between the operating system and the program code. This way, you can run Java programs on almost any platform. Main drawback is, that Java is slower than other languages. Consider using an other, platform dependent solution, if cross platform compatibility is not needed.
How do you Write a C program to print a Series of Odd Numbers and Even Numbers.?
Reference:http:cprogramming-bd.com/c_page2.aspx# strange number
Example problem using nested if statement in C programming?
if (i<0) if (j<0) printf ("i<0 and j<0");
else printf ("What's now? Where this else belongs to? It's i>=0 or i<0 and j>=0?");
The answer is:
if (i<0) if (j<0) printf ("i<0 and j<0");
else printf ("i<0 and j>=0");
Of course you can use brackets:
if (i<0) {
if (j<0) printf ("i<0 and j<0");
else printf ("i<0 and j>=0");
}
or
if (i<0) {
if (j<0) printf ("i<0 and j<0");
} else printf ("i>=0");
How do you write a c program which accepts a positive integer and displays the number of digits?
#include
#include
void main()
{
unsigned long int num;
int i=0;
clrscr();
printf("Enter the digit\n");
scanf("%lu",&num);
while(num!=0)
{
num=num/10;
++i;
}
printf("Length=%d",i);
getch();
}
Can you overload destructor for your class?
No. Classes can only have one destructor, whether you define one yourself or allow the compiler to generate one for you. The compiler-generated destructor is public by default, does not release any memory allocated to any class' member pointers, and is non-virtual, which are the three main reasons for defining your own.
Functions have many uses. Although it is possible to write all code within a single function (the main function), code becomes harder to read. By separating the code into smaller, simpler functions with meaningful descriptive names, complex code becomes that much easier to both read and maintain. That is, the code becomes self-documenting so there is less need for comments which would otherwise become a distraction.
Each function should be designed such that it does the absolute minimum amount of work required to fulfil its purpose and does that work as efficiently as possible. Although functions can be expensive to call and return, a well-written function can be inline expanded by the compiler thus eliminating the function call altogether. Thus functions become a programming tool which can drastically reduce the amount of duplicate code we need to write.
Ideally, a function should be small enough so that all the code within that function will fit on screen at once. This usually means writing a huge number of low-level functions that do very little work by themselves, and then using these low-level functions as the building blocks for more complex, higher-level functions.
How do you draw a rhombus in c program?
C++ has no built-in graphics functions as graphics are platform-specific. You need a graphics library that provides a suitable API for your platform and its hardware in order to output graphics in C++. The code you use will therefore be dependant upon that library.
union is similar to structure .The distinction is in terms of storage. In structure each member has it own storage location but in union all the members use the same location. It can handle only one member at a time.
example.
union u
{
int a;
char b[4];
};
A union may contain structure(s) and a structure may contain union(s).
A structure (or an union) may contain unnamed unions (and structures), a useful feature and worth getting to know.
Example:
typedef union MYUNION {
. struct {
. . int x;
. . int y;
. } int_coord;
. struct {
. . double x;
. . double y;
. } dbl_coord;
} MYUNION;
It's a fragment of memory shared by multiple variables.
What is self referential structure?
It is exactly what it sounds like: a structure which contains a reference to itself. A common occurrence of this is in a structure which describes a node for a linked list. Each node needs a reference to the next node in the chain.
struct linked_list_node {
int data;
struct linked_list_node *next; // <- self reference
};
Write a source code using C programming to find the area of a trapezium using functions?
#include<stdio.h>
#include<conio.h>
# define PI 3.14
void main()
{
float radius,area;
clrscr();
printf("Enter the Radius of the Triangle:");
scanf("%f",&radius);
area=PI*radius*radius;
printf("Area = %f",area);
getch();
}
What will happen if you do not use break statement?
Everywhere in the code when there is no 'break', the running will continue with the next instruction. Example:
for (i=0; i<3; ++i) {
printf ("i=%d: ", i);
switch (i) {
case 2: printf ("two ");
case 1: printf ("one ");
case 0: printf ("zero ");
}
printf ("\n");
}
The output:
0: zero
1: one zero
2: two one zero
How do you write a c program to sort ten names in descending order?
If you are using the String class to store your names then you can use the < or > operators to compare the order, alphabetically, they appear in.
String names[3];
int numberOfNames = 3;
names[0] = "abc";
names[1] = "dfg";
names[2] = "hij";
printf("befores%s\n", names[0],names[1],names[2]);
for( int i = 0; i < numberOfNames-1; i++ )
{
for( int j = 0; j < numberOfNames; j++ )
{
if( names[j] < names[j+1] )
{
names[j].swap( names[j+1] );
}
}
}
printf("afters%s\n", names[0],names[1],names[2]);
output:
before abcdfghij
after hijdfgabc
*********************************************************************
this will give correct answer
#include
int main(){
int i,j,n;
char str[20][20],temp[20];
puts("Enter the no. of string to be sorted");
scanf("%d",&n);
for(i=0;i<=n;i++)
gets(str[i]);
for(i=0;i<=n;i++)
for(j=i+1;j<=n;j++){
if(strcmp(str[i],str[j])>0){
strcpy(temp,str[i]);
strcpy(str[i],str[j]);
strcpy(str[j],temp);
}
}
printf("The sorted string\n");
for(i=0;i<=n;i++)
puts(str[i]);
return 0;
}
What is the difference between datatype and keyword in c?
data type refers to the kind of value that is held by a particular variable. For ex: an int variable contains integer value, a string holds a alpha numeric value etc.
variable refers to the name of a value using which we can refer to this value.
Ex:
public int age = 28;
here int is the data type and age is the variable.
Creating a program using switch statement and if and else statement?
Not that difficult...
int main (int argc, char **argv)
{
if (argc==1) printf ("No arguments\n");
else printf ("%d arguments\n", argc-1);
goto END;
END:
return 0;
}
Is encapsulation a characteristic of procedural or object oriented programming?
Encapsulation is one of the four pillars of object-oriented programming. The other three are inheritance, polymorphism and abstraction.
How do you write mainframe program?
Nothing special. Of course before you start, you should know how to compile, link, run and debug your programs, but this goes for every platform.
Explain the linked list and multi linked list structures?
I tried my best to explain all Linked List.
For Single Linked List http://www.fansonnote.com/2012/02/single-linked-list/
For Double Linked List http://www.fansonnote.com/2012/02/double-linked-list/
For Multi Linked List http://www.fansonnote.com/2012/02/multi-linked-list/
Hope it will help.
Thanks.
How do you extract the contents of a file in C?
Open it (open of fopen), read the data (read or fread), then close it (close or fclose).
Use of Percent in C programming?
%p is used in a printf statement to show the memory address value of a pointer. It does not show the address of the pointer itself. You can see this with the following program:
#include
int main(void){
int* p;
printf("p: %p x: %x x&: %x\n",p,p,&p);
}
This gave me the following output:
p: 0x33d6d0 x: 33d6d0 x&: bf9a8c10
So %p is a way of formatting the value in a pointer to make it obvious that you are referring to a memory location.
C program to determine sum of squares of all even numbers between 10 to 1000?
main()
{
int i,sumo=0,sume=0,oddno,evenno;
for(i=1,oddno=1,evenno=2;i<=100;++i,oddno=oddno+2,evenno=evenno+2)
{
sumo=sumo + oddno;
sume=sume + evenno;
}
printf("Sum of odd nos = %d And Sum of even nos = %d,sumo,sume);
}