How do you break the infinite loop program in turbo c plus plus without break key?
In short, you don't. By definition, an infinite loop is one that has no exit condition. For example:
while( 1 );
When execution reaches this line, the program will get no further. It will continually execute this same line of code because the only way for this loop to exit is when the literal constant 1 becomes the literal constant 0 -- which would clearly be impossible.
By the same token, the following lines are also infinite loops:
do while( 1 );
for(;;);
Infinite loops of this kind are completely useless in production code. Apart from the fact they do nothing remotely useful, an infinite loop renders the program completely invalid. And yet we hear the term infinite loop being used in code all the time.
The truth is that while we do use the term infinite loop, it is not strictly infinite. What we really mean is that although the loop statement needn't have an exit condition, the body of the loop does!
By way of an example, consider the following infinite loop:
while( 1 )
{
if( !rand() )
break;
}
Here, the loop statement is clearly infinite, but the body contains the all-important exit condition. In this case, the loop continually produces random numbers in the range 0 to 32767. If the number is zero, then control passes to the break statement at which point the loop ends and execution continues at the statement following the closing brace of the loop. Thus on every loop there's a 1 in 32768 chance the loop will end. There's a remote possibility the loop may never end however it's highly unlikely. Note that in its current form, the random numbers will produce the same sequence over an over and the loop will therefore execute the same number of times every time the program is run. But even if we seed the random numbers to produce a different sequence each time, the loop will exit after just a few seconds at most. The odds of never ever producing a zero are remote in the extreme.
So that's the so-called infinite loop -- which is not really infinite after all. But to answer the question, we break out of an infinite loop by providing at least one exit condition within the body of the loop. If the program is to be run within an event-driven environment (such as Windows), we might periodically test the message queue to see if a specific key sequence is pending (such as ESC) and prompt the user to save the current state of the loop so that it can continue at a later date before gracefully exiting the loop. By the same token, we should also check for a program exit message (perhaps the user clicked the close window button, or even chose to shutdown Windows in the middle of the loop) and we must cater for those eventualities too.
Ultimately, how you exit an infinite loop will depend entirely upon the purpose of the loop. There is no one-size-fits-all solution. But there must be at least one exit condition that must logically fire at some point in time. If not, the loop is truly infinite and will completely invalidate your program.
A non-standard C header file that contained functions specific to accessing functions of MS-DOS. There is no need to use this header file, as there are standard libraries included in all major compilers that replace the functions in DOS.H.
According to the documentation on MSDN, the following code should create an uncompressed volume texture DDS file that's 32x32x32 in size. Re-scale as you see fit. Note: a 128x128x128 RGBA texture will take up 8 MB of VRAM! #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> #define DDSD_CAPS 0x00000001 #define DDSD_HEIGHT 0x00000002 #define DDSD_WIDTH 0x00000004 #define DDSD_PITCH 0x00000008 #define DDSD_PIXELFORMAT 0x00001000 #define DDSD_MIPMAPCOUNT 0x00020000 #define DDSD_LINEARSIZE 0x00080000 #define DDSD_DEPTH 0x00800000 #define DDPF_ALPHAPIXELS 0x00000001 #define DDPF_FOURCC 0x00000004 #define DDPF_RGB 0x00000040 #define DDSCAPS_COMPLEX 0x00000008 #define DDSCAPS_TEXTURE 0x00001000 #define DDSCAPS_MIPMAP 0x00400000 #define DDSCAPS2_CUBEMAP 0x00000200 #define DDSCAPS2_CUBEMAP_POSITIVEX 0x00000400 #define DDSCAPS2_CUBEMAP_NEGATIVEX 0x00000800 #define DDSCAPS2_CUBEMAP_POSITIVEY 0x00001000 #define DDSCAPS2_CUBEMAP_NEGATIVEY 0x00002000 #define DDSCAPS2_CUBEMAP_POSITIVEZ 0x00004000 #define DDSCAPS2_CUBEMAP_NEGATIVEZ 0x00008000 #define DDSCAPS2_VOLUME 0x00200000 int depth = 32; int width = 32; int height = 32; unsigned int header[32]; int main( int argc, char * argv[] ) { if( !argv[1] !strstr( argv[1], ".dds" ) ) { fprintf( stderr, "Usage: noise output.dds\n" ); return 1; } unsigned int cnt = width*height*depth*4; unsigned char * buf = new unsigned char[ cnt ]; while( cnt-- ) { buf[cnt] = rand()>>7; } memset( header, 0, sizeof( header ) ); header[0] = ' SDD'; header[1] = 124; header[2] = DDSD_CAPS | DDSD_PIXELFORMAT | DDSD_WIDTH | DDSD_HEIGHT | DDSD_DEPTH | DDSD_PITCH; header[3] = height; header[4] = width; header[5] = width*4; header[6] = depth; header[19] = 32; header[20] = DDPF_RGB|DDPF_ALPHAPIXELS; header[22] = 8; header[23] = 0xff0000; header[24] = 0xff00; header[25] = 0xff; header[26] = 0xff000000; header[27] = DDSCAPS_TEXTURE | DDSCAPS_COMPLEX; header[28] = DDSCAPS2_VOLUME; FILE * f = fopen( argv[1], "wb" ); if( !f ) { fprintf( stderr, "can't create: %s\n", argv[1] ); return 1; } fwrite( header, 4, 32, f ); fwrite( buf, 1, width*height*depth, f ); fclose( f ); fprintf( stderr, "wrote %s\n", argv[1] ); return 0; }
How do you write c plus plus program to display size of the each data type?
The core if it would contain lines like these:
printf ("sizeof (char)=%d\n"
"sizeof (short)=%d\n"
"sizeof (int)=%d\n"
"sizeof (long)=%d\n"
"sizeof (long long)=%d\n"
"sizeof (size_t)=%d\n"
"sizeof (void *)=%d\n"
"sizeof (ptrdiff_t)=%d\n"
"sizeof (va_list)=%d\n"
"sizeof (intptr_t)=%d\n"
, (int)sizeof (char)
, (int)sizeof (short)
, (int)sizeof (int)
, (int)sizeof (long)
, (int)sizeof (long long)
, (int)sizeof (size_t)
, (int)sizeof (void *)
, (int)sizeof (ptrdiff_t)
, (int)sizeof (va_list)
, (int)sizeof (intptr_t)
);
C plus plus library functions for string operations?
You can use "string" class in C++ for string operations or you may use c style string functions as well. #include <string> String class in C++ provides all basic function to operate on strings. you may details descriptin at http://www.cplusplus.com/reference/string/string/
Is the Readng Plus program available for children who read spanish?
"No. Reading Plus is strictly an English company. However that being said, they do have a spanish program like reading plus which is called Spanish Pronto Reading."
How do you use or integrate c plus plus code in visual basic 6?
You can't integrate C++ source code directly into Visual Basic code. In order to make use of code written in another language, including C++, you must compile that source to produce a DLL. You can then link to that DLL via Visual Basic. The only caveat is that you must replace the C++ data types in the function declarations with the equivalent Visual Basic data types, such as 'Byte' for a C++ unsigned char, or 'Single' for a C++ float.
Delete memory release operator in c plus plus?
You can't physically delete memory, you can only delete a pointer to allocated memory, which subsequently releases the memory back to the system. The operator is delete, passing the pointer as the operand. If the pointer points to an array, then you must also use the index operator [] in front of the pointer name.
int main()
{
// pointer to an int type with value 100
int* ptr_int = new int(100);
// ... use pointer ...
// release the integer
delete ptr_int;
// pointer to an array 100 int types (with undefined values)
int* ptr_int_array = new int[100];
// ... use array ...
// release the array
delete [] ptr_int_array;
return(0);
}
Where can you get oop e balaguruswamy with C plus plus solutions?
solution of object oriented programming e balagurusamy
Why inherit function is not called?
Inherit is not a function. It is a class derivation where some of the methods and attributes of the new class inherit from a parent class.
Write c plus plus program for new and delete operator using class?
#include<iostream>
class foo{
int m_data;
};
int main()
{
foo* p=new foo;
delete( foo), foo=NULL;
return(0);
}
Which member can not be access from main in c plus plus?
A private member can only be accessed from within a method of the class.
(Not 100% certain what the question means. If this answer is not sufficient, please restate the question, giving more details as to what is being asked.)
What is the best programming language for mods in gta 5?
The best and only language for GTA V mods is C++, specifically Visual C++. For the PC version you can also use C# to an extent, but for the majority of work C++ is the only option. If you don't have Visual Studio you can download the free community edition.
Advantages of Typeless programming language?
* In a typeless language, a variable can contain any kind of value (numeric, string, boolean). * Typeless languages are very flexible and dynamic, resulting in quick turn around of code.
Can you divide pointer variables?
No, but if you really want that, use type-cast, for example:
printf ("main=%p=5*%lx\n", main, ((long)main)/5);
Of course it is good for nothing at all.
What is different between while and for loop in c plus plus?
Although both can achieve very similar loops, the one you use for a specific loop usually comes down to whichever seems more intuitive to you. In terms of performance, one method may be slightly more efficient than the other, however there are no general rules that can be applied; you must test each case by comparing the machine code or by physically timing the loops with a high performance event timer (HPET). In my experience, the performance difference is so negligible it is not worth the effort. Background activity has a far greater impact on performance.
Describing the differences between every possible loop you might create would take me a lifetime, but there are a couple of subtle differences that are worth pointing out.
Infinite Loopsfor(;;){
} // infinite for loops do not require a condition.
while( true ){
} // infinite while loops MUST have a condition.
To break out of an infinite loop you must test for one or more conditions within the loop itself, and call break to exit the loop when a condition is met. You can also call continue to start the next iteration before reaching the end of the current iteration.
Stepping LoopsWhen stepping through a series of values, the for() loop is usually the better choice, especially if the step must occur AFTER each iteration. Consider the following similar loops:
for( int x=0; x<10; ++x ){
// if we place continue here, ++x will execute before the next iteration begins.
}
int x=0;
while( x<10 ){
// if we use a continue here, ++x will not execute. We could be here forever!
++x;
}
Another point to bear in mind here is that with the for()loop, x will fall from scope when the loop finishes. If x must remain in scope, initialise x before entering the for() loop. With the while() loop, x is still in scope when the loop finishes so if x must fall from scope, do not use the while() loop.
do...while LoopsThe do...while loop is quite different from for()and while() loops, so it is worth mentioning here. Both for() and while() loops test a condition BEFORE the loop begins execution. If the condition is false, the loop may not execute at all. But a do...while loop is guaranteed to enter the loop AT LEAST once, because the condition is tested AFTER the loop begins, at the end of the loop just before it begins to iterate.
int x = 0;
do{
// Whatever you place here will execute at least once.
// If we place continue here, execution jumps to the while(condition) first.
}while(++x != 10)
A class can inherit as many interfaces as it needs, using multiple-inheritance. And yes, the same interface can be inherited by two different classes.
Multiple inheritance occurs when a class is derived from two or more base classes. For instance, if you have a list class and a node class, then you could easily inherit from both to produce a tree class, since a tree is both a list and a node. The tree therefore inherits the interface of both a list and node and combines them into a single entity.
Just as a square and a circle are types of shape, a circle class and a square class can both inherit from the same generic shape class. Since both the circle and the square have a common interface, collections of shapes are possible, regardless of their actual type. Taxonomy is another example of this. Cats and dogs and bats are all types of mammal, thus they can all share a common interface provided by a mammal class. By the same token, mammals, reptiles and birds can share a common interface provided by an animal class. Moreover, trees, flowers and other vegetation share a common interface with animals: the class of living things. How accurately your classes reflect reality is entirely up to you: if you wish to model a dog kennel, then a common dog class is all you need to provide the base class for all dogs.
If a data-item is declared as a protected access specifier then it can be accessed?
A class method or attribute (data item) that is declared protected can be accessed only by methods of the same class or by methods of derived classes of the class.
int lastLargestIndex(int a[],int n) //a=array, n= number of elements in array
{
int max=a[0],maxp=0; //max=largest no., maxp= position of largest no.
for(int i=0;i<n;i++)
if(a[i]>=max)
{
max=a[i];
maxp=i;
}
return maxp;
}
What structure can be execute a set of statements only under certain circumstances?
Decision structure.
What are the similarities between constructor overloading and function overloading?
The only similarity is that both constructor and function overloads are distinguished by their signature -- the number and type of their arguments. Functions differ in that they also have a return type, which is also part of the signature, whereas constructors have no return type, not even void.
How do you display the square root symbol on output screen using C Plus Plus?
The the square root symbol can be displayed by using ASCII code
cout<<"press alt251"; pressing alt251 "��"
What math levels do i need to become a good computer programmer?
If your programming is purely recreational then you don't really need specific maths levels though something equivalent to a Maths GCSE would help. If it's something you want to do further than purely fun like at a university/college level then many places ask for a Maths A-Level. Really it depends on what you are programming though some degree of higher Maths education will really help.