What is a type cast in c plus plus?
A type cast is an override within an expression that causes the compiler to generate conversion code and to treat the item as if it had a different type.
int a = 13;
int b = 4;
float c;
c = a / b; /* result is 3, the integer value of 13 divided by 4 */
c = (float) a / b; /* result is 3.1, the floating value of 13 divided by 4 */
In this case, the (float) keyword was the typecast. Note also that it was not necessary to typecast b, because the compiler recognizes the mixed mode expression.
What is public access specifier?
An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are:
1. Public
2. Protected
3. Default and
4. Private
Private is the most restrictive access modifier whereas public is the least restrictive. Default is the access protection you get when you do not specifically mention an access modifier to be used for a java object.
Java programming does not run by just a single piece of class that has the whole functionality. You have hundreds of classes that interact with one another, passing data between them and returning output to the user of the system. So it is very important for members of one class to access members of another. Here members may refer to variables, methods and even classes. So, this is where the access modifiers come into picture. The modifier associated with every member of the class determines what level of visibility that member has.
What is the constructors in class?
A class is simply the definition of a data type. A constructor is a special method of a class that is automatically invoked whenever an object of that type is instantiated, and is used to initialise the object's data members.
What is the difference between static and non static class members in java?
Static data members are different from automatic ones in the way that their lifetime is equals to the lifetime of your program. Even if you have declared static members inside of function (class) other than main();
What is the difference between a class and a function in C plus plus?
You cannot point at a class, you can only point at an instance of a class, which is simply another term for an object. The class is essentially the object's type; it define's the object's behaviour, but is not the object in and of itself. The class also defines a pointer's type, so we can point at instances of a class and access the the object it represents through indirection.
What is the importance of visual C plus plus?
C++ is simply a specification of the language while VC++ is a specific implementation of the language that should follow the specification but doesn't. The differences are relatively minor, but can cause problems porting code between compilers. Implementations that follow the specification are generally considered better as they are more compliant with each other. However, if all you want to do is write Windows programs, VC++ is as good a choice as any.
What is the difference between structure oriented and object oriented programming language?
the main difference is that structured programming deals with the flow of execution, and not, primarily, with the data. The mathematical basis for structured programming has to do with the elimination of arbitrary jumps (GOTOs) in favor of code blocks and functions. In particular, "information hiding" as it relates to data isn't fully developed in structured programming; structured programming has to do with the organization of the code, rather than the data, and pure structured programming passes data around in the form of function arguments (conceptually, "on the stack").
In contrast, object oriented programming primarily deals with data issues. The object/class paradigm promotes clean, flexible organization of data in the same way that structured programming promotes clean, flexible organization of code. In a pure object oriented approach, the flow of program execution is treated as bits of behavior associated with the packets of data that are "objects".
What programming framework does C plus plus use?
C++ doesn't use a framework; it is a general purpose, object oriented programming language derived from the C programming language. Specific implementations, such as Microsoft Visual C++, make use of frameworks.
How to write a program that converts inches into centimeters feet yards and meters in C plus plus?
#include <iostream>
using namespace std;
int main()
{
double meter, cent;
cout<<"Enter value in meters";
cin>>meter;
cent=meter*100;
cout<<meter<<" meters"<<" = "<<cent<<" centimeters;
system("pause");
return 0;
}
to convert more than one number put the whole program in a for loop
What are C plus plus intrinsic functions?
Most functions are available from libraries, however some functions are built-in to the compiler itself. A built-in function is therefore an intrinsic function.
Some intrinsics are only available as built-in functions while others also have standard function equivalents. You can choose to use some or all intrinsics either by using the #pragma compiler directive or via a compiler optimisation switch, such as /Oi in MSVC++, or indeed both.
Intrinsic functions are typically inline expanded to eliminate the overhead of a function call, and some will also provide information back to the compiler in order to better optimise the emitted code.
Intrinsics affect the portability of code but are generally more portable than inline assembler. Indeed, some architectures do not support inline assembler, thus intrinsics are nothing if not essential where optimal code is a requirement.
Your compiler's documentation should provide a complete list of the intrinsic functions available for each platform it supports, along with the standard function equivalents.
What are the differences between assembly and high-level language c plus plus?
Assembly language is a procedural language with a low-level of abstraction between the source code and the resulting binary code. Assembly language is entirely machine specific, and the onus is therefore upon the programmer to code specifically for that machine. The code cannot be transferred and assembled on a different architecture -- it must be re-written in its entirety.
High-level languages such as C++ have a high level of abstraction between the source code and the resulting binary code, with a high degree of separation between the source and the machine. This abstraction renders the source code far more portable than low-level languages as the onus is now upon the compiler to produce the machine specific code, not the programmer. C++ utilises a combination of structured and object-oriented programming to achieve this abstraction, allowing the programmer to create highly robust code that is not only easier to read, but easier to maintain, regardless of its complexity.
How is memory allocated for structres in C plus plus?
Memory is allocated to struct types exactly the same way as memory is allocated to class types. Memory is allocated to each member variable in the same order as they are declared, according to the size of each member plus any padding required for alignment purposes (which is typically the word size of the architecture).
The least-derived base class is always allocated first and, where multiple-inheritance is employed, the order of inheritance in the derived class declaration determines the order of allocation for its base classes. However, the order of the base classes has no effect upon the combined size of those base classes, only upon the order in which they are allocated.
Note that in order to minimise wasted memory in each individual class, it is generally best to declare class member variables in descending order of size. Consider the following, where base1 and base2 have the exact same member types but in different orders, such that base2 occupies less memory than base1.
derived has no members save those it inherits from base1 and base2, thus its total size is the sum of its base classes.
#include<iostream>
struct base1
{
char a;
int b;
char c;
char d;
};
struct base2
{
int e;
char f;
char g;
char h;
};
struct derived: public base1, public base2 {};
int main()
{
std::cout<<"base1 is "<<sizeof(base1)<<" bytes"<<std::endl;
std::cout<<"base2 is "<<sizeof(base2)<<" bytes"<<std::endl;
std::cout<<"derived is "<<sizeof(derived)<<" bytes"<<std::endl;
}
base1 is 12 bytes
base2 is 8 bytes
derived is 20 bytes
Write a c plus plus program for finding the inverse of a given matrix?
#include<stdio.h>
#include<math.h>
float detrm(float[][],float);
void cofact(float[][],float);
void trans(float[][],float[][],float);
main()
{
float a[25][25],k,d;
int i,j;
printf("ENTER THE ORDER OF THE MATRIX:\n");
scanf("%f",&k);
printf("ENTER THE ELEMENTS OF THE MATRIX:\n");
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
scanf("%f",&a[i][j]);
}
}
d=detrm(a,k);
printf("THE DETERMINANT IS=%f",d);
if(d==0)
printf("\nMATRIX IS NOT INVERSIBLE\n");
else
cofact(a,k);
}
/******************FUNCTION TO FIND THE DETERMINANT OF THE MATRIX************************/
float detrm(float a[25][25],float k)
{
float s=1,det=0,b[25][25];
int i,j,m,n,c;
if(k==1)
{
return(a[0][0]);
}
else
{
det=0;
for(c=0;c<k;c++)
{
m=0;
n=0;
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
b[i][j]=0;
if(i!=0&&j!=c)
{
b[m][n]=a[i][j];
if(n<(k-2))
n++;
else
{
n=0;
m++;
}
}
}
}
det=det+s*(a[0][c]*detrm(b,k-1));
s=-1*s;
}
}
return(det);
}
/*******************FUNCTION TO FIND COFACTOR*********************************/
void cofact(float num[25][25],float f)
{
float b[25][25],fac[25][25];
int p,q,m,n,i,j;
for(q=0;q<f;q++)
{
for(p=0;p<f;p++)
{
m=0;
n=0;
for(i=0;i<f;i++)
{
for(j=0;j<f;j++)
{
b[i][j]=0;
if(i!=q&&j!=p)
{
b[m][n]=num[i][j];
if(n<(f-2))
n++;
else
{
n=0;
m++;
}
}
}
}
fac[q][p]=pow(-1,q+p)*detrm(b,f-1);
}
}
trans(num,fac,f);
}
/*************FUNCTION TO FIND TRANSPOSE AND INVERSE OF A MATRIX**************************/
void trans(float num[25][25],float fac[25][25],float r)
{
int i,j;
float b[25][25],inv[25][25],d;
for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{
b[i][j]=fac[j][i];
}
}
d=detrm(num,r);
inv[i][j]=0;
for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{
inv[i][j]=b[i][j]/d;
}
}
printf("\nTHE INVERSE OF THE MATRIX:\n");
for(i=0;i<r;i++)
{
for(j=0;j<r;j++)
{
printf("\t%f",inv[i][j]);
}
printf("\n");
}
}
Input and output statements in C?
For input: scanf("%d",&the value u wanna get into pgm); For output: printf("%d",the value u wanna give to out); Note: u ve to be sure in the letter u put after %.because it ll change depends on variable.eg:int,char,floatdouble,string,decimal,hex,oct..etc Rgds, BM
Objects are constructed. You can't make a new object without invoking a constructor. In fact, you can't make a new object without invoking not just the constructor of the object's actual class type, but also the constructor of each of its superclasses including the Object class itself! Constructors are the code that runs whenever you use the keyword new.
What is Microsoft visual c plus plus 2005 redistributable?
A redistributable file(not just an MS VC++ 2005 redistributable) is a file that the software vendor allows you to redistribute along with derivative works that you provide using their software. Most redistributables are DLL's, which are shared libraries. The software product depends on these libraries, and derivative work that you write, such as programs using that compiler, also depend on these libraries. In terms of C++, examples are the run-time library and the class libraries for Microsoft Foundation Classes. The file is "redistributable" because the license you have permits you to bundle that file with your product, usually contained within an installer package. You need to very carefully read the license agreement, and make sure you know exactly what is considered "redistributable", and what is not. An example of a non-redistributable file would be a debug version of the run-time library. Usually, Microsoft redistributables are contained in a REDIST directory created when you install the product but, again, read the license agreement.
How do you overload function call and Array sub-scripting operators?
Overloading the "function call" operator, i.e. operator()(), can be achieved by defining a method with the following form:
For example, here's how it would look in the simplest case (no argument or return value):
class Callable {// ...public:voidoperator()() {// do something interesting}// ...};
Overloading the array subscript operator, i.e. operator[](), is just as easy. This operator always takes a single argument (the subscript). Here's a template for a method which overloads this operator:
For example:
class Subscriptable {// ...public:doubleoperator[](unsigned index) {// compute and return a double}// ...};
Code for palindrome checking in C programming?
bool is_palindrome (char* str) {
if (str==0) return false;
int len = strlen (str);
if (len==0) return false;
int len2 = 0;
char* str2 = malloc (len + 1);
char* begin;
char* end;
char c;
for (int i=0; i<len; ++i) {
c = tolower (str[i]);
if ((c>='a' c<='z') (c>='0' c<='9')) str2[len2++] = c;
}
begin = str2;
end = begin+len2-1;
while ((*begin==*end) && (begin<end)) { ++begin; --end; }
free str2;
result = end<=begin;
}
What is a function prototype in C and C plus plus?
A function prototype is basically a definition for a function. It is structured in the same way that a normal function is structured, except instead of containing code, the prototype ends in a semicolon.
Normally, the C compiler will make a single pass over each file you compile. If it encounters a call to a function that it has not yet been defined, the compiler has no idea what to do and throws an error. This can be solved in one of two ways.
The first is to restructure your program so that all functions appear only before they are called in another function.
The second solution is to write a function prototype at the beginning of the file. This will ensure that the C compiler reads and processes the function definition before there's a chance that the function will be called.
For example, let's take a look at a few functions form a linked list implementation.
// Sample structures
struct linked_list_node {
int data;
struct linked_list_node *next;
};
struct linked_list {
int size;
struct linked_list_node *root;
};
// Function Prototypes
void deleteLinkedList(struct linked_list *list);
void deleteNodes(struct linked_list_node *node);
// Actual functions:
// deletes the given linked list
void deleteLinkedList(struct linked_list *list) {
if( list != NULL ) {
// delete nodes
deleteNodes(list->root);
// lose the pointer
list->root = NULL;
// delete actual list
free(list);
}
}
// deletes all nodes starting at node
void deleteNodes(struct linked_list_node *node) {
if( node != NULL ) {
// deallocate next, if it exists
if( node->next != NULL ) {
deleteNodes(node->next);
// lose the pointer
node->next = NULL;
}
// deallocate node
free(node);
}
}
What is the concept of flag in c plus plus?
we will give sujika then output will be ok
here first give su ofter jika then print ok
b/w su nd jika there no letters give answer plz
What is the datatype of a class?
While there are obvious data types like primitives (boolean, char, byte, short, int, long, float, double) and arrays, really any class which stores some form of information can be considered a data type. Objects like String, BigInteger, and the whole Collections framework also belong in this category.
C programming code for newton raphson method to solve quadratic equation?
yes
This is the codes for Newton-Raphson method for solving Quadratic equations
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define F(x)(x*x*x)-(4*x)
#define FD(x)(3*x*x)-4
#define MAXIT 20
void main()
{
int count;
float x0,x1,fx,fdx;
clrscr();
printf("NEWTON-RAPHSON METHOD\n");
printf("---------------------\n");
printf("initial value:");
scanf("%f",&x0);
count=1;
begin:
fx=F(x0);
fdx=FD(x0);
x1=(x0-(fx/fdx));
if(fabs((x1-x0)/x1)<0.00001)
{
printf("The root is:%f\n",x1);
printf("Iteration is:%d\n",count);
}
else
{
x0=x1;
count=count+1;
if((count<MAXIT));
goto begin;
}
getch();
}
What is mean by redirection in c plus plus?
Redirection applies to the standard input/output devices. Although it is up to the user to decide which device provides input and which provides output for your program, the programmer can choose to redirect those devices as they see fit. However, it is important that the programmer restore the original devices as soon as they have finished with them.
The following example demonstrates one way of redirecting the standard input/output devices programmatically:
#include <iostream>
#include <fstream>
#include <string>
void f()
{
std::string line;
while (std::getline(std::cin, line)) // input from stdin
{
std::cout << line << "\n"; //output to stdout
}
}
int main()
{
std::ifstream in("in.txt");
std::streambuf *cinbuf = std::cin.rdbuf(); // save old buf
std::cin.rdbuf(in.rdbuf()); // redirect std::cin to in.txt!
std::ofstream out("out.txt");
std::streambuf *coutbuf = std::cout.rdbuf(); // save old buf std::cout.rdbuf(out.rdbuf()); // redirect std::cout to out.txt!
std::string word;
std::cin >> word; // input from the file in.txt
std::cout << word << " "; // output to the file out.txt
f(); // call function
std::cin.rdbuf(cinbuf); // reset to standard input again
std::cout.rdbuf(coutbuf); // reset to standard output again
std::cin >> word; // input from the standard input
std::cout << word; // output to the standard input
}
Why is it a good practice to initialize pointers?
A pointer is initialized by assigning the address of some object to it ...
int a; // an integer
int *pa; // a pointer
pa = &a; // initialize the pointer
(*pa); // use the pointer
... by allocating memoryand assigning that address to it ...
int *pa; // a pointer to an integer
pa = malloc (1 * sizeof(int)); // allocate
if (pa == NULL) {... exception processing ...}
(*pa); // use the pointer
... or by doing address computation with it ...
int a[10]; // an array of integers
int *pa; // a pointer to an integer
pa = &(a+3); // initialize to the fourth element
(*pa); // use the fourth element