Why you use hash in c plus plus?
#define is a pre-compiler directive which is used to define a macro. All occurrences of the defined macro within your source code are replaced by the macro definition prior to compilation. In other words, your code is altered to produce an intermediate file which is actually compiled, just as if you'd copy/pasted the macro definition throughout your code. However, the end result is that the compiler cannot identify any problems within your macros since they will no longer exist in the intermediate file. Macros are not type safe, thus they are generally frowned upon, especially when they are used to define complex functions. However, correct usage of macros can greatly simplify your code and ultimately permit the compiler to build different versions of your code, depending upon which definitions you define. For instance, you will typically use slightly different versions of some functions depending on whether you are building a debug or release version of your code, and will typically #define DEBUG for debug builds. You can also cater for cross-platform coding by filtering platform-specific functions using macro definitions. You alter the type of the build simply by defining the appropriate definitions, either within the code itself (using #define), or via the compiler's pre-processing command line switches, or a makefile script.
FUNCTION OVERLOADING:
- when we define two functions with same name,in same class(may be) distinguished by their signatures
- resolved at compile time
- same method bt different parameters in each of them
FUNCTION OVERRIDING:
- when we redifine a function which is already defined in parent class
- resolved at run time
- changing the existing method
How is garbage collection done in c plus plus?
Garbage collection is used to released resources which were previously used by the application(s) which is called garbage collector. Garbage collection allows to prevent memory leaks which are the main problem of old style of programming.
C plus plus program for overloading operator?
#include<iostream>
#include<string>
// a simple class
class my_class
{
private:
std::string m_caption;
public:
// default constructor
my_class (std::string caption): m_caption (caption) {}
// read-only accessor
const std::string& get_caption() const { return m_caption; }
};
// output stream insertion operator overload
std::ostream& operator<< (std::ostream& os, const my_class& obj)
{
os << obj.get_caption();
return os;
}
int main()
{
// call default constructor
my_class object1 ("This is the caption for object1");
// exercise output stream insertion operator overload
std::cout << object1 << std::endl;
}
How do you learn the c plus plus language?
The same way you understand any computer language -- by learning the language. However, the learning curve is steep so it helps if you learn a much simpler language first, such as BASIC, so that you are familiar with basic concepts such as variables, arrays, loops and so on.
Where you can include a header file in the program?
You can include a file with the #include directive at any place you want to. You just have to consider that the compiler will see the total source file as if you had copied the contents of each include file at the point where you included it, and it will parse and process the total source file accordingly.
That said, header files, a subset of included files, are generally #include'd at the top of the source file. Again, it all depends on what is in the include file.
What are 5 different types of modifiers in c plus plus?
There are five type modifiers in C++:
long
short
signed
unsigned
[] - the array subscript
The first four are used solely to modify the characteristics of the int type. Signed and unsigned can also be applied to the char and wchar_t types while long can also be applied to a double. If no type is specified, int is assumed. The array subscript modifier can be applied to any type including modified types and pointers to a type.
Excluding arrays, pointers and the built-in bool type, C++ has the following fundamental (built-in) types:
char
signed char
unsigned char
wchar_t
signed wchar_t
unsigned wchar_t
int
signed int
unsigned int
short int
signed short int
unsigned short int
long int
signed long int
unsigned long int
long long int
signed long long int
unsigned long long int
float
double
long double
A plain (unmodified) char may be signed or unsigned (implementation defined) but must behave exactly as an explicitly signed or unsigned char would. However, all three are deemed separate types in C++. Similarly with wchart_t. However, an int is implicitly signed.
The length of each fundamental type is implementation defined, but can be found by using the sizeof operator either upon the type itself or upon an instance of the type. The standard library <type_traits> header can be used to determine other information, particularly useful in static (compile-time) assertions.
The C++ standard library also provides additional types of specific size, including int8_t, int16_t, int_32_t, int64_t, uint_8_t, uint_16_t, uint32_t and uint64_t. Note that the _t suffix is often used to denote that a type is really a typedef (an alias) for a modified type, such as size_t (an unsigned int). However wchar_t is typically implemented as a built-in type. All fundamental types can be found in <cstddef> (which is usually included when you include any standard library header such as <iostream>) while the fixed-length integers can all be found in <cstdint>.
List of graphics commands in c plus plus?
That's easy. There aren't any. C++ is designed to be as generic as possible, thus it provides generic text-based output only. Graphics output is platform-specific and is therefore not provided by the C++ standard. You can, of course, use graphics in C++, but you need a library and API that is specific to your platform and hardware. Most IDEs will provide an appropriate library, but as soon as you use graphics in your programs, you will generally lose the benefit of compiling your code on other platforms, unless you write your code specifically to cater for other non-generic libraries that are suitable for compilation upon other platforms.
What is the difference between array and normal data type?
Data typing is static, but weakly enforced
What is the difference between prefix and postfix increment operator in c plus plus?
Both the prefix and the postfix increment operators increment the operand. The difference is what is the value of the expression during the evaluation of the expression. In the prefix form, the value is already incremented. In the postfix form, it is not.
int a = 1;
int b = ++a;
// both a and b are now equal to 2
int a = 1;
int b = a++;
// a is equal to 2 and b is equal to 1
How to write a C program to generate Fibonacci series up to 10 elements and store in array?
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
int swap(int* , int*);
int main()
{
int c=0;
int b=1;
int max;
cout<<"Enter the maximum limit of fibbonacci series = ";
cin>>max;
if(max>0)
{
cout<<c<<endl;
}
else
{
exit (EXIT_FAILURE);
}
for(int i=0;i<max;i++)
{
c=b+c;
swap(&b,&c);
if(c<max)
{
cout<<c<<endl;
}
else
{
break;
}
}
getch();
return 0;
}
int swap(int *x,int *y)
{
int z;
z=*x;
*x=*y;
*y=z;
return z;
}
Why you are using strcpy in c plus plus?
In short, you don't. strncpy is deemed unsafe as it has potential to cause buffer overruns. To copy strings safely in C++, use std::string instead.
For examples and syntax, see related links, below.
What program do they use to make c plus plus compilers?
The first generation C++ compiler was written in C. Newer generations of C++ compilers are written using the previous generation of C++, however some implementations also use assembler, either in part or in whole.
Bear in mind that one of the first programs ever written for a computer was an assembler. Before assembler, all code had to be written in machine code, the native language of the computer, which was labour intensive and prone to error. But that was exactly how the first generation assembler had to be written. Thereafter, the assembler was used to create the next generation assembler, and the next, until high-level languages began to appear (again, written in assembler), until C finally appeared, which eventually led to C++.
What is rtti in c plus plus programming?
RTTI is runtime type information. It is a basic requirement of the dynamic_cast operator in order to ensure all casts between polymorphic objects within a class hierarchy are done safely. Other cast operators such as safe_cast also utilise RTTI. However, RTTI has an overhead that can be detrimental to performance thus RTTI is often utilised in debug code to verify C-style casts in release code (such as reinterpret_cast) are always done safely. Both static_cast and reinterpret_cast are inherently unsafe, however static_cast does invoke user-defined conversions, whereas reinterpret_cast does not, and should only be used as a last resort. But try telling Microsoft that...
In many cases, RTTI can be eliminated completely by utilising a well-designed class hierarchy with virtual interfaces that avoid the need to cast between object types. In other words, it should not be necessary for any base class to even be aware of any of its derived class' types (let alone their specialities) in order to use them. By calling virtual methods, casting between types is done safely and automatically, behind the scenes, by virtue of the virtual table. Moreover, a v-table has a much lesser overhead than RTTI.
That said, there will be times when RTTI is the only solution to a problem, especially when working with legacy code and libraries for which you have little or no control over. If there's ever any doubt about what a pointer is really pointing at, use RTTI. Better safe than sorry.
Write a program to print n natural numbers using do-while loop?
//(this is just a function, call this as count(n) in your main loop)
void count(int n){
int i = 1;
do{
printf("%d", i);
i++;
} while(i<=n);
}
OOPs stands for Object Oriented Programming then whats that extra s stands for?
As per the website, www.acronymfinder.com, OOPS stands for Object-Oriented Programming and Systems.
Regards,
Anthony
anthonymail@rediffmail.com
// returns n!
int fact(final int n) {
// keep track of factorial calculation in f
// f starts at n, and we will multiply it by all integers less than n
int f = n;
// loop from n-1 down to 2
for(int i = (n - 1); i > 1; --i) {
// increase our total product
f *= i;
}
return f;
}
Can you get STD's when you are a virgin?
The only STDs you can be confident about are those that were specifically tested for. Your partner cannot infect you unless he or she is already infected. However, you can infect your partner if you are infected.
There are several STDs that are not routinely tested for as part of an STD examination. Tests for herpes and HPV are expensive and in the case of herpes not always reliable. Health care providers usually only test for those if there is an indication that someone is infected (for HPV usually an abnormal Pap smear).
Unless you are certain you are entering a long term monogamous relationship and that you have both been extensively tested it is unwise to engage in sexual activity without condoms.
If you are entering a relationship where you are going to have skin on skin sex, without condoms, you could establish some certainty about STDs as follows:
1. HIV test.
2. Herpes test
Its all very gloomy and unromantic doing this, but if you want to do it properly, see a doctor and suggest these three steps.
Structures are a way of storing many different values in variables of potentially different types under the same name. This makes it a more modular program, which is easier to modify because its design makes things more compact. Structs are generally useful whenever a lot of data needs to be grouped together--for instance, they can be used to hold records from a database or to store information about contacts in an address book. In the contacts example, a struct could be used that would hold all of the information about a single contact--name, address, phone number, and so forth.
->A structure is a collection of related elements , possibly of different types , having a single name.
->"each element in a structure is called field".
->A FIELD is a smallest element of named data that has meaning. It has many characteristics of the variable .
->It exits in memory . it can be assigned values, which in turn can be accessed for selection or manipulation.
-> A field differs form variable primarily in that it is a part of structure.
ITS SYNTAX IS:
struct tag name
{
field list;
};
Token separation source code in C Plus Plus?
\\ Token Separation \\
Write a program to identify and generate the tokens present in the given input
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iostream.h>
int key = 0;
char expr[100];
char cont[][20]={"CONTROLS","for","do","while","NULL",};
char cond[][20]={"CONDITION","if","then","NULL"};
char oprt[][20]={"OPERATOR","+","-","*","/","%","<","<=",">",">=","=","(",")","NULL"};
char branch[][20]={"BRANCHING","goto","jump" ,"NULL"};
void checking(char[],char[][20]);
void main()
{
int i,j,l,k,m,n;
char sbexpr[50],txt[3];
clrscr();
cout<<"Enter the expression:";
gets(expr);
for(i=0;expr[i]!=NULL;i++)
{
key=0;
for(j=i,k=0;expr[j]!=32 && expr[j]!=NULL;i++,j++,k++)
sbexpr[k]=expr[j];
sbexpr[k]=NULL;
if(key==0) checking(sbexpr,cond);
if(key==0) checking(sbexpr,cont);
if(key==0) checking(sbexpr,branch);
if(key==0)
{
for(m=0;sbexpr[m]!=NULL;m++)
{
key=0;
txt[0]= sbexpr[m];
txt[1] = NULL;
if(key==0) checking(txt,oprt);
if((key==0) ((sbexpr[m]>=97 && sbexpr[m]<=122) (sbexpr[m]>=65 && sbexpr[m]<=90)))
{
cout<<"\n"<<sbexpr[m]<<"------->"<<"Identifier\n";
key = 1;
}
}
}
if(key == 0)
{
cout<<"\n"<<sbexpr<<"------->"<<"Address\n";
key = 1;
}
}
getch();
}
void checking (char expr[],char check[][20])
{
for(int i=1;strcmp(check[i],"NULL")!=0;i++)
{
if(strcmp(expr,check[i])==0)
{
cout<<expr<<"------>"<<check[0]<<"\n";
key = 1;
}
}
}
What is difference between Near structure and far structure?
We haven't used near and far addressing for well over a decade. It was common in older systems where memory was addressed by segment and offset. For instance, on a 32-bit system we might use 16-bits to address the segment and 16-bits to address the offset within that segment. If we were referring to an offset within the current segment then we'd use a 16-bit near pointer, but if we needed to refer to another segment then we'd use a 32-bit far pointer. Today we use a normalised pointers.
What is pointer to an object in c plus plus?
A pointer is simply a variable that stores a memory address. Thus a pointer to an object is simply a variable that stores the memory address of an object. Since pointers are variables, they require memory of their own. Pointers may also be constant, which simply means you cannot change what they point to. Pointers can also be dereferenced to provide indirect access to the memory they point to -- hence they are known as pointers. However, unlike C, pointers are not the same as references. In C++, a reference is simply an alias for a memory address and requires no storage of its own.
Write a c plus plus program to add two matrix using arrays?
Matrix Add
/* Program MAT_ADD.C
**
** Illustrates how to add two 3X3 matrices.
**
** Peter H. Anderson, Feb 21, '97
*/
#include <stdio.h>
void add_matrices(int a[][3], int b[][3], int result[][3]);
void print_matrix(int a[][3]);
void main(void)
{
int p[3][3] = { {1, 3, -4}, {1, 1, -2}, {-1, -2, 5} };
int q[3][3] = { {8, 3, 0}, {3, 10, 2}, {0, 2, 6} };
int r[3][3];
add_matrices(p, q, r);
printf("\nMatrix 1:\n");
print_matrix(p);
printf("\nMatrix 2:\n");
print_matrix(q);
printf("\nResult:\n");
print_matrix(r);
}
void add_matrices(int a[][3], int b[][3], int result[][3])
{
int i, j;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
result[i][j] = a[i][j] + b[i][j];
}
}
}
void print_matrix(int a[][3])
{
int i, j;
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%d\t", a[i][j]);
}
printf("\n");
}
}
Can you connect to database in unix environment using c or c plus plus languages?
At the simplest level, a database is simply a data container. As such an array can be considered a database. However, when we think of a database we usually imagine a container that combines one or more related tables of data, that allows us to easily modify data, to search for data, and so on. Databases are typically disk-based centralised repositories (data servers) containing a massive amount of data, while end-users (data clients) are really only concerned with a small amount of that data (a subset). Data can also be generated by the database, such as when returning the number of records in the database that match a specified criteria.
Database Management Systems (DBMS) are the simplest way to make and use a database as all the functionality you need is readily available, all you need do is connect to the DBMS and query it, typically using a text-based script such as SQL (structured query language). MySQL is a popular choice because it is open source and can be used under the terms of the Gnu Public Licence (GPL).