What does call-by-Value and call-by-Reference mean?
When we swap values in function, that time "Call by value" swaps copied value not the exact values. so it doesn't reflect on main function. But in case of "Call by
reference", we swap actual value which is available at that reference or address.
Is c plus plus is pure object oriented?
No. C is not object-oriented, it is a procedural language.
C++, while object-oriented, is not purelyobject-oriented. One of the requirements for a pure object-oriented language is that everything is an object. C++ still has primitive data types (int, long, double, etc.), and so is not purely object-oriented.
What is a linked list used for?
A linked list is used in computer science to store data as a series of related nodes. Linked lists are used as the basis for abstract data types when programming. The chief advantage of a linked list is that data can be added or removed from the list without having to reorganize the whole list. A drawback to linked lists can be that it is difficult to sort, organize, or recall specific information from the list.
Time complexity of selection sort?
Merge sort (or mergesort) is an algorithm. Algorithms do not have running times since running times are determined by the algorithm's performance/complexity, the programming language used to implement the algorithm and the hardware the implementation is executed upon. When we speak of algorithm running times we are actually referring to the algorithm's performance/complexity, which is typically notated using Big O notation.
Mergesort has a worst, best and average case performance of O(n log n). The natural variant which exploits already-sorted runs has a best case performance of O(n). The worst case space complexity is O(n) auxiliary.
The programming language C is an enhanced version of the programming language C?
Yes, the C++ programming language is an enhanced version of the C programming language.
Of note: to increment a variable by 1 in C, you could type myInt++ (i.e. for(int i = 0; i < 1; i++). C++ was named C++ because it is one step above C (C + 1).
Write a program WAP to print a given integer in the reverse order?
int n; // the number you want to reverse
int rev_n = 0;
while (n > 0) {
// shift rev_n digits left
rev_n *= 10;
// put rightmost digit of n onto right of rev_n
rev_n += n % 10;
// remove rightmost digit of n
n /= 10;
}
How function can be nested in c?
A function can call other functions (or itself), but a function-definition cannot be nested in another function-definition:
int main (void)
{
void wont_compile (void) { puts ("Won't compile"); }
wont_compile ();
return 0;
}
Why should you declare variables?
Declaring of a variable in Java refers to creating a variable of a particular data type.
Example:
int x = 10;
Here we are declaring an integer variable X and initializing it to a value of 10
What is the difference between array of pointers and pointer to an array?
An array of pointers is that for eg if we have array of 10 int pointers ie int *a[10] then each element that which is stored in array are pointed by pointers. here we will have ten pointers. In pointer to an array for eg int(*a)[10] here all the elements that is all the ten elements are pointed by a single pointer.
What is multidimensional arrays?
A two-dimensional array is the simplest multi-dimensional array and is implemented as a one-dimensional array where every element is itself a one-dimensional array. We can imagine a two-dimensional array as being a table of rows and columns where every row is an array in its own right.
A three-dimensional array is simply a one-dimensional array of two-dimensional arrays, which can be imagined as being an array of tables. Extending the concept, a four-dimensional array is a table of tables.
Multi-dimensional arrays may be jagged. That is, a two-dimensional array may have rows of unequal length. Unlike regular arrays, jagged arrays cannot be allocated in contiguous memory. Instead, we use the outer array (the first dimension) to store pointers to the inner arrays. An array of strings (character arrays) is an example of a two-dimensional jagged array.
What is the c plus plus program that finds max value in the array of size n?
#include
using std::cout;
using std::endl;
double maxValue(double arr, const intarrSize);
int main()
{
const int arrSize = 10;//Size of the array you are going to use
double arr[arrSize] = {0.0};
cout << endl << "Enter the array elements..."
for ( int i = 0; i < arrSize; i++ )
{
cout << endl << "Enter " << (i + 1) << " element:";
cin >> arr[i];
}
cout << endl << "Max value is: " << maxValue;
system("PAUSE");
return 0;
}
double maxValue(double arr, const intarrSize)
{
double max = arr[0];
for ( int j = 0; j < arrSize; j++ )
{
if ( max < arr[j])
{
max = arr[j];
}
}
return max;
}
What is the meaning of conio in C?
Hi,
Conio.h is a header file which have functions declaration. One of them is clrscr() function. This function have its prototype in conio.h.
clrscr() function is used to clear the screen. Thus, whenever u called clrscr() function u r required to define conio.h header file in your program.... Similarly there are many functions in conio.h....
Hope it will help u....
Write a program to accept n from user and to display all even numbers between 1 to n in javascript?
man mnn g gt grand theft auto or grand theft walrus
Program demonstrate Fibonacci series using recursion?
#include<stdio.h>
#include<conio.h>
int fib(int);
int f=1,j=0,k=0,i=0,c;
void main()
{
int l;
clrscr();
printf("Enter limit\n");
scanf("%d",&l);
f=0;
printf("%d\n",f);
f=1;
printf("%d\n",f);
for(c=0;c<l;c++)
{
f=fib(l);
printf("%d\n",f);
}
getch();
}
int fib(int n)
{
while(i<n)
{
if(i<=n)
{
i++;
j=k;
k=f;
f=k+j;
fib(1);
return f;
}
}
}
output-
enter limit
4
0
1
1
2
3
5
Advantages of register variable?
Register variables are a special case of automatic variables. Automatic variables are allocated storage in the memory of the computer; however, for most computers, accessing data in memory is considerably slower than processing in the CPU. These computers often have small amounts of storage within the CPU itself where data can be stored and accessed quickly. These storage cells are called registers. Normally, the compiler determines what data is to be stored in the registers of the CPU at what times. However, the C language provides the storage class register so that the programmer can ``suggest'' to the compiler that particular automatic variables should be allocated to CPU registers, if possible. Thus, register variables provide a certain control over efficiency of program execution. Variables which are used repeatedly or whose access times are critical, may be declared to be of storage class register. Also these register variables are used in huge projects the tiny program developers are not interested to include these register variables, because the tiny programs never requires more time complete its job. These register variables may be used to store constant values so as to make use of it anywhere in the programs. main{ register float a=0;}
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i,a[100],sum=0;
float avg;
printf("Enter number of students");
scanf("%d",&n);
printf("Enter the marks score by students one by one");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
sum=sum+a[i];
}
avg=sum/n;
printf("The average is %f", avg);
getch();
}
Do while loop program in c for printing odd numbers?
#include<stdio.h>
main()
{
int a,i=1;
printf("Enter max no");
scanf("%d",&a);
do
{
printf("%d",i);
i=i+2;
}while(i<=a);
}
What are the differences between a struct data type and a class data type in c plus plus?
A struct declares all members public by default, whereas a class declares all members private by default. That is really the only difference. Structs are from C and classes from C++, you can use both structs and classes in C++ but only structs in C.
/* ellipses, ..., used to emulate indentation */
int strcmp (const char* s1, const char* s2) {
... while (s1 != NULL && s2 != NULL) { /* scan both strings */
... ... if (*s1 < *s2) return -1; /* first string less */
... ... if (*s1 > *s2) return 1; /* first string greater */
... ... s1++;
... ... s2++;
... }
... if (s1 == s2) return 0; /* strings equal or both empty */
... if (s1 != NULL) return 1 else return -1; /* first string longer(1) / shorter(-1) */
}
A slightly less computation-intensive version is:
int strcmp(const char* s1, const char* s2)
{
... if (s1==s2)
... ... return 0;
... while (*s1)
... ... if (*s1++^*s2++)
... ... ... if (--s1<--s2)
... ... ... ... return -1;
... ... ... else
... ... ... ... return 1;
... return 0;
}
What are the rules of defining variable?
All variable names must begin with a letter of the alphabet or an underscore ( _ ). The rest of the characters may be any of those previously mentioned plus the digits 0-9.
Which is the keyword used to access the variable declared as global variable in another file?
To be able to access a variable declared in one file/class from another file/class you need to declare that variable as "public".
Doing this is a very bad coding practice because exposing a variable of a class to be available publicly to other classes is totally against the Java object oriented concepts of Encapsulation and Data hiding. So, preferably you shouldn't be doing this.
However, a better way to do this is, declare the variable as private and have public accessor methods through which you can access this variable. This will ensure that your data is protected even if it is available outside the class
Is it better to use malloc or calloc to allocate memory?
In general using malloc is faster, since calloc initializes the allocated memory to contain all zeroes. If this is what you want, however, then calloc can be used. The results can vary among different operating systems and environments, though. Memory allocation in an OS that uses floating blocks in heaps, such as Microsoft Windows and MacOS, should use the OS-native memory allocators instead. "Use malloc() almost always and calloc() almost never." The reason is that the initialization to zero that calloc() performs is usually not very helpful: - The initialization to "all-bits-zero" is not necessarily the same as initialization to "all-data-zero." C says very little about the representation of values in memory, nothing at all for floating-point or pointer values. On many machines all-bits-zero representations will in fact correspond to f.p. zeroes or null pointers, but this is not guaranteed by the language and there have been machines where the correspondence did not hold. If you get in the habit of using calloc() to initialize f.p. and pointer items, you may be heading for trouble. - Usually, one allocates a chunk of dynamic memory in order to store something in it -- and when you store something in it, you'll overwrite whatever was there before. Thus, the initialization performed by calloc() is usually not needed anyhow. There are occasional exceptions where all- bits-zero initialization is helpful, but they are unusual.
What is stdio.h means in c language?
#include <stdio.h> means that the compiler needs to grab all function definitions, implementations, variables, etc. from that file. In this case, stdio stands for "Standard Input/Output". An example of a function in stdio.h is "printf".