Can you overload static functions in c plus plus?
Yes, but overloads cannot differ by return type alone. The signatures must differ by the number and/or the type of the arguments.
What are the advantages of using a symbolic constant rather than a literal constant in c plus plus?
The main two I can think of:
Write a c plus plus program to sort the names in asecending order using array of objects?
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
int main()
{
std::vector<std::string> str_array = { "John", "Bill", "Alan", "Craig"};
std::sort (arr.begin(), arr.end());
}
Why do you need assembly language?
Assembly language is more human-readable than machine language. Generally, statements in assembly language are written using short codes for the instruction and arguments, such as "MOV $12 SP", as opposed to machine language, where everything is written as numbers. Assembly language can have comments and macros as well, to ease programming and understanding.
Generally, programs called "assemblers" transform assembly language to machine language. This is a relatively straightforward process, there being a clear 1-to-1 transformation between assembly and machine language. This is as opposed to compilers, which do a complicated transformation between high-level language and assembly.
--------------------------------------------------------------------
ASSEMBLY is the key word to define the difference between Machine Language and Assembly. . Assembly language assembles steps of MACHINE CODE into SUB-ROUTINES defined by simple text words:
Such as: the assembly command 'ADD' may represents 20-30 machine commands.
Can private members of a class be inherited?
All fields and methods of a class are inherited:
public class A
{private int x =10;public int XVal{get{return x;}}}
public class B:A
{public B(){x = 20;}}
What are the advantages of using a recursive function in c?
Advantages:
Through Recursion one can Solve problems in easy way while
its iterative solution is very big and complex.
Ex : tower of Hanoi
You reduce size of the code when you use recursive call.
Disadvantages :
Recursive solution is always logical and it is very
difficult to trace.(debug and understand)
Before each recursive calls current values of the varibles
in the function is stored in the PCB, ie process control
block and this PCB is pushed in the OS Stack.
So sometimes alot of free memory is require for recursive
solutions.
Remember : whatever could be done through recursion could be
done through iterative way but reverse is not true.
How do you write a c plus plus program to print aaaa aaab aabb abbb bbbb?
#include<iostream>
#include<string>
#include<algorithm>
bool compare_no_case (const char a, const char b)
{
return tolower(a) < towlower (b);
}
int main()
{
std::string s {"This is the string to be sorted!"};
std::cout << "Unsorted:\t"" << s << ""\n";
std::sort (s.begin(), s.end(), compare_no_case);
std::cout << "Sorted\t:"" << s << ""\n";
}
Explain how a private data of a base class can be accessed by publicly derived class?
The only way that private attributes of a base class can be accessed by a derived class (protected or public) is through a protected or public method in the base class.
The protected or public method is the interface through which access to the attributes is defined and controlled.
What is sub classing in c plus plus?
Class in C++ is just the same meaning as in any other OO(object-oriented) languages. In the world of OO, anything are classes, which have properties, function to work. In other words, class is a method to organize things to work together.
Can you Write a program in c plus plus to display the multiplication table?
void printTable() {
}
printf("\n");
printf(" ");
for (c = 0; c <= 10; ++c) {
printf(" -");
}
printf("\n");
// calculations
int r;
for (r = 0; r <= 10; ++r) {
// row headers
printf("%2d|", r);
// calculation for the current row
for (c = 0; c <= 10; ++c) {
printf("%4d", (r * c));
}
printf("\n");
}
}
How do you Assign an address to an element of pointer array?
Pointers were always difficult subject to understand. I would suggest to read several tutorials and spend some time playing with them.
Explanation:
/* create array of two pointers to integer */
int *aaa[2];
/* setting first pointer in array to point to 0x1212 location in memory */
aaa[0] = (int *)0x1212;
/* allocate memory for the second pointer and set value */
aaa[1] = malloc(sizeof(int));
*aaa[1] = 333;
/* if you want to can make first item to point to the second,
now arr[0] pointer address changed to the same as aaa[1] pointer */
aaa[0] = aaa[1];
/* print aaa[1] address and later print value */
printf("LOCATION: %X\n", (unsigned int)*(aaa + 1));
printf("VALUE: %d\n", **(aaa + 1));
/* exact the same here, but different way of how I wrote pointers */
printf("LOCATION: %X\n", (unsigned int)aaa[1]);
printf("VALUE: %d\n", *aaa[1]);
If you would do the same with 0 element of array, which points to 0x1212 memory location you would get some kind of number or Bus error if you accessed restricted memory place (for example the beginning of memory).
I hope this I did not make you more confused than you are.
What is the role of switch statement in c plus plus?
Switch is an alternative to using a long sequence of if...else if... statements where each conditional expression is essentially the same, evaluating to the same data type but with different values.
For instance:
if(x==1) statement_1;
else if(x==2) statement_2;
else if(x==3) statement_3;
else statement_4;
The above can also be written:
switch(x)
{
case(1): statement_1; break;
case(2): statement_2; break;
case(3): statement_3; break;
default: statement_4;
}
Most would regard the second version as more readable as there's only one conditional expression to evaluate.
What are the disadvantage of conventional programming language?
ali asghari:
It shouldn't be a problem, as long as:
1) The features are well-designed, e.g. having one sort function that takes a few options, rather than many sort functions that do slightly different things
2) The features are namespaced - e.g. mathematical functions are in a Maths module or object, that way user function and variable names are less likely to collide with language base features, and be broken by language version increments
3) The features are properly documented in an organised way - there's no point in offering a facility if the programmer doesn't know it's there or the specs give no clue on how it's supposed to be used
4) The features don't duplicate one another - e.g. different names for the same function, different possible syntaxes for the same meaning, etc. which makes code harder to read for programmers familiar with the "other" syntax
5) The features aren't out of scope for the language (e.g. there's no point in features for 3D graphics acceleration in a language designed for web servers), as this will increase memory requirements, and thin out performance efforts.
So, the disadvantages would be if one of these pitfalls is encountered, and the potential problems caused
An array name is a pointer constant?
An array's name is not a constant pointer; it's not even a pointer! An array name is a reference to the array itself. Unlike pointers, references have no memory of their own, therefore a reference cannot be constant (only what it refers to can be constant). A reference is nothing more than an alias for a memory address. Since there is no separate storage for references, you cannot reassign references while they remain in scope. So, in that sense, it behaves like a constant pointer. But a pointer is a variable, so even if declared const, it requires memory of its own in order to store the memory address it points to.
Example:
int a[10];
int * const p = a; // const pointer
assert( *p &a ); would cause an assertion. Likewise, assert( p != &p); proves that p must reside in a separate memory address from that referred to by a. It has to: pointers are variables even when they are declared const.
Can cin and cout be used in the function definition of user defined functions in C plus plus?
The cin and cout entities (they are not statements) are C++ iostream library objects that allows access to "standard input" and "standard output". In C++, the statement cout << "Hello World!"; is similar to the C statement printf("Hello World!\n"); Similarly, cin >> variable; allows reading from standard input to a variable.
What is a feature in c that is not in c plus?
C is a structured programming language which is feature of C which made it a powerful language when it was new in market.
But after C++ was developed structured programming was considered as disadvantage due to development of Object Oriented Programming Language.
What is the use of using namespace STD in c plus plus programming?
No, the use of 'namespace std' is not compulsory. You can specifiy it on any object reference. Specifying 'namespace' simply provides a default value.
Contrast ...
using namespace std;
cout << "Hello world!" << endl;
... with ...
std::cout << "Hello world!" << std::endl;
How many main functions can a c plus plus program have?
1. In C language, you cannot compile a source-file if it has two (or more) functions with the same name.
2. You cannot link a program if it has two (or more) global (ie: non-static) functions with the same name.
Difference between while loop and do loop?
The difference between "do while" and "do until" is that a "do while" loops while the test case is true, whereas "do until" loops UNTIL the test case is true (which is equivalent to looping while the test case is false).
The difference between a "do ...while" loop and a "while {} " loop is that the while loop tests its condition before execution of the contents of the loop begins; the "do" loop tests its condition after it's been executed at least once. As noted above, if the test condition is false as the while loop is entered the block of code is never executed. Since the condition is tested at the bottom of a do loop, its block of code is always executed at least once.
To further clear your concept on this, understand the syntax and description of the two loop types:
while
The while loop is used to execute a block of code as long as some condition is true. If the condition is false from the start the block of code is not executed at al. The while loop tests the condition before it's executed so sometimes the loop may never be executed if initially the condition is not met. Its syntax is as follows.
while (tested condition is satisfied)
{
block of code
}
In all constructs, curly braces should only be used if the construct is to execute more than one line of code. The above program executes only one line of code so it not really necessary (same rules apply to if...else constructs) but you can use it to make the program seem more understandable or readable.
Here is a simple example of the use of the while loop. This program counts from 1 to 100.
#include
int main(void)
{
int count = 1;
while (count <= 100)
{
printf("%d\n",count);
count += 1; // Notice this statement
}
return 0;
}
Note that no semi-colons ( ; ) are to be used after the while (condition) statement. These loops are very useful because the condition is tested before execution begins. However i never seem to like these loops as they are not as clear to read as the do ...while loops. The while loop is the favorite amongst most programmers but as for me, i definitely prefer the do ...while loop.
do ....while
The do loop also executes a block of code as long as a condition is satisfied.
Again, The difference between a "do ...while" loop and a "while {} " loop is that the while loop tests its condition before execution of the contents of the loop begins; the "do" loop tests its condition after it's been executed at least once. As noted above, if the test condition is false as the while loop is entered the block of code is never executed. Since the condition is tested at the bottom of a do loop, its block of code is always executed at least once.
Some people don't like these loops because it is always executed at least once. When i ask them "so what?", they normally reply that the loop executes even if the data is incorrect. Basically because the loop is always executed, it will execute no matter what value or type of data is supposed to be required. The "do ....while" loops syntax is as follows
do
Note that a semi-colon ( ; ) must be used at the end of the do ...while loop. This semi-colon is needed because it instructs whether the while (condition) statement is the beginning of a while loop or the end of a do ...while loop. Here is an example of the use of a do loop.
include
int main(void)
{
}
Disadvantages of learning c and c plus plus?
* It is pointers that give C its power. but they are highly insecure.
makes it vulnerable.
* c doesn't support inheritance,makes it more complex to use coz everything has to be written from scratch.
AnswerC allows the programmer all the rope the programmer could ever want. It is up to the programmer not to hang him/her self. Hanging your self is the drawback.
Difference of c plus plus and fox pro?
C++ is a generic, general purpose, object-oriented, structured programming language used to produce native machine code programs. FoxPro is a procedural language and Database Management System (DBMS).
What is the language of compiler of c plus plus?
C++ is a general purpose, cross platform, object-oriented programming language that compiles to native machine code. Although it supports OOP, it does not rely on it. You can mix C++ code with C-style code and even Assembly Language routines.
How c plus plus is a procedure based language?
C is both.
The characteristics of a procedural oriented language: assignment operators (:= in C)
The characteristics of a structured programming language: block of codes ({} in C) for if-else, while-, for- loops, subroutines, etc.
What is prototyping in c plus plus?
A prototype in C++, as well as in C, is a declaration of a function and its parameters, including the types of the function and parameters. It does not actually create (define) the code for the function - it only identifies (declares) it to the compiler.
It is used to enforce type checking for functions and parameters, and it is used to declare the function for use in other code prior to the function actually being defined, such as in a different compilation unit or library. Headers, for instance, contain mostly prototypes.
What is the function on endl in c plus plus?
std::endl means end line, and is typically used to insert a new-line character in an output stream using the insertion operator (<<). This is really no different to inserting the '\n' character code to the output stream, however it also serves to flush the output buffer by writing all unwritten characters to the output stream.
When used as a global function, std:endl(ostream& OS) can be used to insert a new-line character and flush the given output stream. The return value is a reference to the output stream itself thus it can be used in compound statements that make use of the return value.