Give 6 characterstics of object oriented programming?
Actually these characterstics may differ from books to books. This is in general: #Data abstraction #Data Encapsulation #Inheritance #Polymorphism #Dynamic Linking #Static Binding Some books consider Objects & Classes also as one among these characteristics.
What is a C program to print the number of an array in reverse order?
#include<iostream>
#include<vector>
int main()
{
std::vector<int> Array;
Array.push_back (42); // insert
Array.pop_back(); // delete
}
used in defining goto statement in C++.
tells the program which part of the code it should skip to.
example:
void main()
{
x: // This is the label
cout<<"\n Wikipedia rocks" ;
cout<<"\n Google rocks" ;
goto x; // starts executing from x:
getch();
}
// Warning!! this loop will be infinite, plz do not run it, its only for example sake!!!
What type of variable is visible to every module and the entire program?
If you are talking about a class in Java, a variable encapsulated by a class is called an instance variable b/c everytime you create an object with that class, each object has its own set of the variables declared.
Differentiate between interpreter and complier?
Compiler compiles code into binary program, which is then ran by operating system or a virtual machine(Java or C#)
Interpreter steps trough code, doing instructions one after another, without any compilation or optimization.
By definition, recursion means the repeated application of a recursive definition or procedure. It is used to define an object in terms of itself in computer science and mathematical logic.
What is global variable in C programming?
A global variable is a variable that is declared at global scope, rather than file, namespace, function, class or nested scope. Global variables are usually declared with external linkage within a header and initialised in one (and only one) source file. Any file that includes the header (which includes the source file that initialised the global variable) then has unrestricted access to the variable. It is globally visible and any code can alter it.
Global variables should be used sparingly and only when absolutely necessary. If the vast majority of the functions in your program require access to a particular variable, then a global variable makes perfect sense and is by far the simplest solution. However, a variable that is only used by a handful of functions can hardly be described as a global entity, thus it has no place within the global namespace and should be scoped to those functions that actually require it instead.
C program for solving gauss seidal method?
#include<stdio.h>
int main()
{
double matrix[10][10],a,b, temp[10];
int i, j, k, n;
printf("Enter the no of variables: ");
scanf("%d", &n);
printf("Enter the agumented matrix:\n");
for(i = 0; i < n ; i++){
for(j = 0; j < (n+1); j++){
scanf("%lf", &matrix[i][j]);
}
}
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
if(j>i){
a = matrix[j][i];
b = matrix[i][i];
for(k = 0; k < n+1; k++){
matrix[j][k] = matrix[j][k] - (a/b) * matrix[i][k];
}
}
}
}
printf("The Upper triangular matrix is: \n");
for( i = 0; i < n; i++){
for(j = 0; j < n+1; j++){
printf("%.2f", matrix[i][j]);
printf("\t");
}
printf("\n");
}
printf("\nThe required result is: ");
for(i = n-1; i>=0; i--){
b = matrix[i][n];
for(j = n-1 ; j > i; j--){
b -= temp[n-j]*matrix[i][j];
}
temp[n-i] = b/matrix[i][i];
printf("\n%c => %.2f",97+i, temp[n-i]);
}
}
What is parameter constructor?
C++ permits us to achieve this objects bt passing argument to the constructor function when the object are created . The constructor that can take arguments are called parametrized constructors
Example:-
class abc
{
int m,n;
public:
abc(int x,int y); //paramererise constructor
................
.................
};
abc::abc(int x,int y)
{
m=x;n=y;
}
How do you write a C program which runs independent of the compiler No need to install the compiler?
Any computer program does not need compiler at the time of execution. Compiler is needed to convert a high-level language program into an intermediate machine code. When you run a program, the executable binary runs, and that is what you get after compilation, etc. Summary: your Q is incorrect. Please read about compiler, and linker to understand the concept. You cannot write c or c++ code and run it without a compiler. a compiler translates a high level language (c, c++, java) into basic computer code (binary) which is composed of 1's and 0's (101001111001). but you can run it without a compiler if it has already been turned into an executable or an application by another computer.
What is the Programming environment?
All desktop computers are composed of at least two main parts: a monitor or display device, and a case where the computer's internal systems are stored. Most commonly, this case is a separate "tower" that is connected to the monitor, but some desktops have the monitor and other hardware integrated into one unit. An operating system loaded on a hard drive allows the computer to display an interactive environment.
What is historical development of C Language?
Bjarne Stroustrup found that OOP languages like Simula and BCPL incorporated features that enabled large and complex software to be developed much more easily than with the more traditional procedural languages, such as C, where the separation of data and the methods that operated upon that data were a hindrance, making code difficult to both write and maintain. However, Simula was too slow to be practical while BCPL was fast but too low-level.
C was the most popular language of the day as it was capable of producing compact and efficient machine code for a wide-variety of hardware, thus he decided to base his new language on C which he began to develop in 1979. As well as Simula, he borrowed ideas from other languages including ALGOL 68, Ada, CLU and ML, and removed some of C's idiosyncrasies such as the unnecessary use of typedef when declaring a struct. Initially, the new language provided classes and derived classes, strong typing, inlining and default arguments. Since it was largely based on C he called his new language 'C with Classes'.
However, the key ingredient was the compiler, which he dubbed Cpre. Coming up with a new language (even one based upon an existing language) is one thing but if it cannot be interpreted or compiled into machine code then it is ultimately useless. However, Cpre wasn't so much a compiler as a translator. All it really did was convert his new language into C source code which could then be compiled using any C compiler.
In 1983, 'C with Classes' had been renamed C++ (pronounced see-plus-plus). In C, the ++ operator is the increment operator, thus C++ literally means the successor to C (ignoring the fact that C++ is the postfix increment operator which evaluates to C, not C+1). By this time, Stroustrup had incorporated new features including virtual functions, function and operator overloads, references, constants and single-line comments, as well as developing an actual compiler which he called Cfront.
In 1985, the first edition of The C++ Programming Language was published (written by Stroustrup himself), followed by the first commercial release of C++. This was followed by release 2.0 in 1989, which now incorporated multiple inheritance, abstract classes, static member functions, const member functions and protected members. In 1990, The Annotated C++ Reference Manual was published (also written by Stroustrup), followed by publication of his second edition of The C++ Programming Language in 1991, by which time C++ now incorporated templates, exceptions, namespaces, new casts and the Boolean type.
At this point the C++ standard library began to evolve, beginning with the stream I/O library and eventually the standard template library. In 1998, C++ was officially standardised under the informal name C++98 (ISO/IEC 14882:1998). Much of that standard was based upon Stroustrup's earlier work, The Annotated C+ Reference Manual. Since then, C++ has been continually revised and updated in line with the C++ standards committee, which Stroustrup still chairs to this day. The current standard is C++11 which, amongst other things, includes the introduction of a move constructor to complement the existing copy constructor. The next major revision is expected in 2017, informally known as C++17.
What is the time complexity for searching an element in an array?
If the array is unsorted, the complexity is O(n) for the worst case. Otherwise O(log n) using binary search.
Can you use visual c plus plus for window programming in c language?
... yes?
The question doesn't really make any sense. Any language can be used to program a computer, so long as you have a compiler for it. There definitely are both C and C++ compilers for Microsoft Windows, therefore you can write device drivers in it if you want.
Heck, you could theoretically write device drivers in LISP or BASIC if you wanted; I personally wouldn't, but it could be done.
What is the Algorithm for exchanging values of two variables?
There are three primary algorithms to exchange the values of two variables.
Exchange with Temporary Variable
temp = a;
a = b;
b = temp;
Exchange Without Temporary Variable Using Exclusive Or
a = a ^ b;
b = b ^ a;
a = a ^ b;
Exchange Without Temporary Variable Using Arithmetic
a = a + b;
b = b - a;
a = a - b;
What Pointer in Data Structure?
No, pointer is not a data type but a reference to an object. Pointers are used to refer back to an object which can be anything from a large data value or a collection of values or objects.
If you ask the address of an element, like char, int, etc., the address you will get will be the address of the first byte. Only the first byte is saved in the pointer, and then you can manipulate the upcoming bytes.
For example you declare a structure of 12 bytes and you name it myStruct.
let's say that the address of this structure is the address 0x00400001 <- this is the 1st byte.
The second is 0x00400002 and so on till the 12th byte which is 0x0040000C.
Then you declare a pointer to point to myStruct like that:
myStruct *pointer;
The variable pointer is 4 bytes. It doesn't matter if the structure is 12 bytes or 100 bytes or 1 byte. The address of anything in 32-bit systems is always 4 bytes.
In this example the pointer variable contains the address of myStruct which is 0x00400001 <- the 1st byte of the structure.
The pointer might be a data structure because like any other data types, the pointer is always 4 bytes (in 32-bit systems). For 64bits systems which is 8 bytes, the pointers of a 32bit program would logically be the half of them empty like 0x00000000 00400001
New line character in c and how to use it?
In code, you'd actually do something like so: '\n'.
Actually, the ASCII code of the Line Feed is 10 (0A hex), and the code of the Carriage Return is 13 (0D hex).
What is difference between virtual base class and virtual function?
A virtual class allows children classes to inherit multiple classes that all share a common ancestor. Without this property, the child class would contain multiple copies of the same parent class. A virtual function is a function, with a body, defined in a parent class that may be overridden in the parent class.
How do object oriented design and structure design differ?
Object Oriented programming is a superset of structured programming. Structured programming is as follows:
--Program start
var
var
var
function { ... }
function { ... }
function { ... }
main { ... }
--- Program End
You have units of code, which operate on variables, and are called in reference to those variables, to follow a structure acting on those variables.
Object oriented is as follows:
--- Program Start
object {
var
var
function { ... }
function { ... }
function { ... }
}
var
var
function { ... }
main { ... }
--- Program end
Variables can be objects, which have their own data and functions. Think like C and structures, except structures can have functions "in them" which operate specificly on their own data. Thus, instead of referencing a function (a block of code) and telling it to operate on a variableq you reference an object and tell it to perform an operation, most often on itself, specific to itself, using its own data. Instead of creating units of data to pass to functions which operate on them, you create objects and have them perform operations [on themselves].
Functions attached to objects don't need a specific name; rather than task_struct_sort_children(task) and acl_rules_struct_sort_children(task), you can have task and acl_rules with task->sort_children() and acl_rules->sort_children(), which have completely different specific function but the same logical function, and operate on the specific instance of the object.
structured oriented programming and object oriented programming have some features of similarities, but the distinction between the two is that the former relies to the GOTO statements thus the developer has a tendency to confuse while the latter is subgrouped from objects, classes, methods and hierarchies.
Why there is only one main function in every C programmes?
Try putting 2 main functions in a program and see what happens rather than asking easy for you to resolve questions here.
What do you mean by variable in c?
scope of a variable is the part of the code within which the variable is defined or the part of your code within which the th variable can be used for example
#include<stdio.h>
void main()
{
int variable1
}
now this variable (variable1) that we have used can be used anywhere within the main function .but if i write a code as shown below
#include<stdio.h>
void function1(int a)
void main()
{
int variable1
}
void function1(int a)
{
sum=variable1+variable1;
}
the compiler wouldn't know what variable1 ,being used in function1 is.
we therefore say that variable1 has a scope within the main only
if however we would have written int 'variable1' immediately after #include<stdio.h> then 'variable one would have been a global variable and could have been used anywhere within the code
What is the major components of c programming?
The major components of a class are its members (data and methods) and its interface to those members. All classes have four members by default: the default constructor, the copy constructor, the destructor, and the assignment operator. However, if you declare any constructor (including a copy constructor) you lose the default constructor unless you declare your own. The class interface is defined by the public, protected and private sections of the class declaration. The interface may also be extended via friend classes and friend functions. Public and protected interfaces can also be inherited from existing base classes and/or abstract base classes to create derived classes, which may modify the base class interfaces without altering the base class itself. Private members can never be inherited, however.
The interface can be divided into several key components: construction, destruction, operations, attributes, accessors and mutators. Constructors handle the complete initialisation of the class and every constructor must ensure that a valid object exists whenever an object of the class is instantiated. The destructor is purely responsible for cleaning up any dynamic memory allocated on the heap and owned by the class (memory allocated on the stack is always released automatically). Operations include the assignment operator and any other operator overloads that modify the class in some way, such as the prefix increment operator. Attributes include type-casts and boolean operators such as the equality and greater-than operators, plus any member methods that return information about the class. Accessors return specific member values from the class (getters) while mutators modify those same members (setters).
Why cin and cout are iostream objects?
Most programs require both input and output. By including iostream you gain access to both, along with the most common datatypes and functions within the standard library. If you don't require all the features provided, you can include only what you need instead.
What do you mean by function to pointer?
Detailed difference between structure and array?
1). Structuer is a group of diffrent data type & set of diff. data type element can manupulet by using structuer .It Size is Addition of all Data type size e.g(int,float,char*2+4+1) =7 byte size of structure
2.) Array is Collection of Same data Type Element
it is intege Array , Char Array , ponter Array,Objeact Array etc,