Difference between portability and platform independent?
Platform independence refers to the fact that java compiled code (byte code) can execute on any operating system. A programme is written in a language that can be understood by humans. It could contain words, phrases, or other information that the system doesn't understand.... The Java Byte Code is the intermediate representation in Java.
To learn more about data science please visit- Learnbay.co
What are the features of static data members in c?
A non-static member function has a hidden argument called the this-pointer which points to the data of the specific instance of the class. Static member functions can be called without reference to a specific instance of the class so it is completely what instance if any you mean. You do this by treating them as functions in a namespace with the same name as your class.
Here's an illustrative example:
class CPerson
{ private:
int m_Age; static int m_NumPeople = 0;
public: void SetAge( int Age ){ this->m_Age = Age }; // Correct, if you omit "this->" the compiler will still infer its existance.
CPerson( void ){ m_NumPeople++ };
~CPerson( void ){ m_NumPeople-- };
static int GetAge( void ){ return this->m_Age }; // Wrong, this-> is ambiguous for static functions.
static int GetPeople( void ){ return m_NumPeople}; // Correct, people count is static.
};
There is only one integer m_NumPeople, it behaves like a global variable but the compiler will only let member functions access it since it is private.
m_NumPeople is created with a default value of zero before you even instantiate your first CPerson. As you instantiate CPersons the constructor is called when each instance is created and the instance counter named m_NumPeople is incremented. As these instances are destroyed the destructor decrements m_NumPeople.
Since GetPeople is static you can call it without having access to any instance of the class like so: CPerson::GetPeople();
The compiler has no mechanism to infer which object you called the static function on or even guarantee that the object has ever been instantiated, therefor CPerson::GetAge() is ambiguous and the compiler spits out an error. CPerson::SetAge( 42) is now allowed either. SetAge needs a this-pointer to find the correct instance of m_Age to set.
When you have some instance of the object you use the . operator or -> operator like so: CPerson Nicholas( ); Nicholas.SetAge( 42 ); Now the compiler can uniquely identify the CPerson in question as Nicholas. It will pass the pointer &Nicholas to the SetAge function. Calling conventions vary, but if you're using microsofts visual studio compiler and compiling 32-bit code it will pass the this pointer in the ECX register and the function parameters will be pushed onto the stack in reverse order(but in this case there's only one).
Is c language is heterogeneous?
Programming languages cannot be 'portable', but programs written in C might be portable, if they follow the strictest standards and do not use platform-specific features or functions.
What is the difference between struct in c and c plus plus?
In C, a struct is simply a type that can hold several sub-objects.
In C++, struct is almost the same as "class". It can have member functions, parent structs and classes, etc. The only difference between struct and class is that the members of class are by default private, while the members of struct are by default public. Thus, a standard C struct is also a good C++ struct - simply one that has no member functions and no parents.
Which are the software programming languages?
There are many programming languages all suitable for many purposes. (Except Java, that one is lame)
The largest list of programming languages I could find is at
http://en.wikipedia.org/wiki/Alphabetical_list_of_programming_languages
A programming language is a medium to solve any problem step by step.
Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely.Programming or coding is a language that is used by operating systems to perform the task.Basically there are two different programming approaches; procedure oriented and object oriented. The procedure oriented programming (POP) approach focuses on creating and ordering procedures or a block of code keeping in mind to accomplish a specific job. The key features of this kind of approach are: use of procedures, sequencing of procedures and sharing global data.However, in case of the object oriented programming (OOP) approach the focus is totally towards identifying objects or data and not on creative activities. Now a days most of the high level programming languages such as Java, C#, C++, and Visual Basic are based on object oriented approach.
The main strength is that it gives complete control over the machine at the lowest possible level. The main weakness is that everything must be encoded in terms the machine can understand. For instance, the otherwise simple operation of x = y + z requires that we move the values stored at the addresses identified by y and z into the appropriate CPU user registers, then invoke the appropriate ADD instruction, then move the accumulator register value into the address identified by x. That's a lot of work for an otherwise simple operation.
How should you Swap 2 numbers in a single line?
Swapping two values in a single statement is made possible through a series of three XOR/assign operations, alternating the operands.
Consider the following declarations:
int x = 0;
int y = 1;
The following statement will swap the values of x and y:
x ^= y ^= x ^= y; // swap
The same statement implemented as a function:
void swap(int &x, int &y){ x ^= y ^= x ^= y; }
What is the recursive solution in data structure?
You cannot have recursion within a data structure:
struct foo {
int x;
foo y; // compiler error
};
This has to fail; there is no end point to the recursion. If a foo is member of a foo, then the member foo also requires a member foo, and so on to infinity...
If a structure needs to refer to another instance of itself, we can use a member pointer:
struct foo {
int x;
foo* y; // ok
};
A pointer works because all pointers are the same length regardless of the pointer's type (the type being referred to).
Using member pointers like this is fundamental to many data structures, such as linked lists:
struct node {
int data;
node* prev; // previous node in the sequence (may be NULL)
node* next; // next node in the sequence (may be NULL)
};
Write a C algorithm to calculate the area of a circle?
#include<stdio.h>
main()
{
int r;
float area;
clrscr();
printf("enter the value of r\n");
scanf("%d",&r);
area=3.142*r*r;
printf("area of circle=%f\n",area);
getch();
}
Write a program to accept two string and display weather they are identical or not?
I assume the program should be case-sensitive. Here is a code of such program:
#include
#include
int main() {
char str1[100];
char str2[100];
printf("Please enter first string: ");
gets(str1);
printf("Please enter second string: ");
gets(str2);
if (strcmp(str1, str2) == 0) {
printf("Strings are Equal.\n");
} else {
printf("Strings are Not Equal.\n");
}
return 0;
}
Testing:
Please enter first string: A
Please enter second string: A
Strings are Equal.
Please enter first string: a
Please enter second string: A
Strings are Not Equal.
If you want to make not case-sensitive comparing before checking you should make both string in lowercase or uppercase.
Here is how it should look:
#include
#include
#include
void upString(char *str);
int main() {
char str1[100];
char str2[100];
printf("Please enter first string: ");
gets(str1);
printf("Please enter second string: ");
gets(str2);
upString(str1);
upString(str2);
if (strcmp(str1, str2) == 0) {
printf("Strings are Equal.\n");
} else {
printf("Strings are Not Equal.\n");
}
return 0;
}
void upString(char *str) {
register int ind = 0;
while (str[ind]) {
str[ind] = toupper(str[ind]);
ind++;
}
}
Testing:
Please enter first string: aaa
Please enter second string: AAA
Strings are Equal.
Please enter first string: aaa
Please enter second string: aAa
Strings are Equal.
Note: You should not be using gets() function in real-world application. There is no way you can limit number of characters to read thus allowing to overflow buffer. It was used only for example.
Can somebody give me the program to find simple interest using friend function in c plus plus?
Here is an example program:
class obj{
public:
float p,n,r,si;
friend void calc( obj temp);
};
void calc( obj temp){
si = (p*n*r)/100;
}
The initialization and function calling is essential.
What is the condition for the overflow in the linked lists?
In linked list if there is no any element inside it than we can say linked list is underflow.
Vmm moves 4k segments called what?
Memory manager works with pages and segments;these are different things, don't confuse them.
Can you delete Microsoft visual c plus?
To delete Microsoft Visual C/C++, like any other Windows program, simply uninstall it using Control Panel / Add-Remove Programs. For additional information, consult the readme that came with the original program.
Public Sub Swap()
dim inta as integer
dim intb as integer
dim intc as integer
inta=4
intb=5
intb=inta
intc=intb
inta=intc
End Sub
Why in c language initgraph doesn't work?
Initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver) then putting the system into
graphics mode.Initgraph also resets all graphics settings (color, palette, current position, viewport, etc.) to their defaults, then resets graphresult to 0.
How do you correct syntax error logical error?
Your IDE should include syntax checking, which highlights errors as they occur (similar to a grammar/spell checker in a word-processor). Attempting to compile a program that contains a syntax error will fail to compile, but it should provide a list of all the errors that need to be fixed. If the error is an obvious one, the error list may include a solution to the problem, but you must make the necessary changes manually -- the syntax checker won't modify any code for you, even if the error is an obvious one, such as using . instead of -> on a pointer.
Can you make private class in c plus plus?
yes it is possible to make a private class in C++ but this class will not solve any purpose.................
When an array name is passed to a function the function?
All array names will implicitly convert to a pointer to the first element in the array. Note that when passing an array to a function, you must also pass the array length as a separate argument because the pointer alone cannot tell you how many elements were actually allocated to the array, let alone how many are currently in use. However, there are some exceptions. For example, a null-terminated string argument does not require a length argument as the null-terminator denotes the end of the character array. User-defined arrays can use a similar technique, using any "unused" or "invalid" value or token to denote the end of the array.
Note that the following function signatures are identical:
void f (int* a, unsigned len);
void f (int a[], unsigned len);
The latter is more readable as it makes it clear the pointer refers to an array.
When passing multi-dimensional arrays, you must add an extra level of indirection for each additional dimension:
void g (int* a[], unsigned rows, unsigned cols); // two-dimensional array
void h (int** a[], unsigned width, unsigned height, unsigned depth); // three-dimensional array
Multi-dimensional arrays can also be null-terminated or terminated by a designated token value. The canonical example of this is a global main function which accepts command line arguments. These arguments are passed through a null-terminated array of null-terminated strings (a two-dimensional array of type char).
int main (char* argv[], int argc) {
assert (argc>=1); // always at least one element
assert (argv[0] != NULL); // the first element is always the executable name (non-NULL)
assert (argv[argc-1] != NULL); // the last element is always non-NULL
assert (argv[argc] == NULL); // the one-past-the-end element is always NULL
return 0;
}
What is the program structure of C language and C plus plus?
There is no single structure to a C++ program. C++ is multi-paradigm and allows programmers to use any combination of C-style programming, object-oriented programming and template metaprogramming using a mixture of primitive built-in types, standard library types and user-defined types.
Which of the following types of memory contain data that cannot be modified by the user?
Pick one:
ROM, PROM, EPROM
write-protected magnetic disk/tape, CD-ROM, DVD-R
write-protected partition/file, other user's or sysadmin's file
code-segment, read-only data-segment, other user's or kernel's code- or data-segment
Write a c program to implement tower of hanoi moves?
/* hanoi.c */
#include <stdio.h>
#include <stdlib.h>
static long step;
static void Hanoi (int n, int from, int to,int spare)
{
if (n>1) Hanoi (n-1,from,spare,to);
printf ("Step %ld: move #%d %d-->%d\n", ++step, n, from, to);
if (n>1) Hanoi (n-1,spare,to,from);
}
int main (int argc, char **argv)
{
int n;
if (argc==1 (n= atoi(argv[1]))<=0) n= 5;
step= 0;
Hanoi (n, 1, 2, 3);
return 0;
}
What is a dosh header file in c?
Not sure what dosh is but dos.h was used by Turbo C/C++ to handle DOS interrupts way back in the early 90s. DOS has largely been consigned to the history books now that Windows is an OS in its own right. Until 1995 it ran on top of DOS, the actual OS, but no-one in their right mind would consider running DOS programs in Windows in this day and age. Console applications are not DOS programs, they are fully-fledged Windows programs but without a fancy GUI.
How do you write a function that counts the number of characters in a string?
As this is probably a homework question, I will give you some pseudo code:
[code]
num_chars = 0
READ ch FROM string
WHILE ch IS NOT END OF STRING
num_chars = num_chars + 1
READ ch FROM string
END WHILE
[/code]
Remember that in C, we use what are called "C-strings". C-strings are a pointer to a continuous group of characters in memory which are terminated by a null character. The null character is '\0', and has an integer value of 0.
The C-string generally points to the first character in the string. To access the value of this character, you must use the dereferencing operator, *. If you want to move to the next character, you simply add 1 to the pointer.
So if you have a C-string:
char *str = "abcd";
then:
*str '\0'
Anything past the null character is undefined. Trying to access this data is considered to be a buffer overflow, and is very dangerous.
Note that c-strings created as pointers should always be treated as immutable, as trying to change them might produce errors. Many compilers will allocate the above string inside the static data area, along with any constants or literals which can not fit inside the immediate field of an instruction.
If you want a mutable string, then declare it as a character array:
char str[] = "abcd";
This method of declaration will explicitly allocate memory on the stack to store the c string in, and as such, the string can be safely manipulated without fear of unintended side effects.