Advantages of new operator over malloc function in c?
1: new operator automatically computes the size of the data object. You need not use the operator sizeof.
2: new operator automatically returns the correct pointer type, so that there is no need to use a type cast.
3: it is possible to initialize the object while creating the memory space.
4: Like any other operator, new and delete can be overloaded.
What can you do with c programming?
C language is used for creating computer applications and also used a lot in writing embedded software/firmware for various electronics, industrial and communications products which use micro-controllers. It is also used in developing verification software, test code, simulators etc. for various applications and hardware products.
How are arguments passed to a function?
Arguments are passed to functions via the thread's function call stack. Every thread has its own call stack, which is a small region of contiguous, fixed-size memory that extends downwards into lower addresses. The stack is allocated when the thread is instantiated and deallocated when the thread terminates thus there is minimal cost in using the stack. Data is pushed and popped from the stack while a stack pointer keeps track of the top of the stack (the lowest unused address).
Can you write a function similar to scanf?
//program for myprintf using variable arguments
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
int compare(const void * var1,const void * var2)
{
if(*(int *)var1 > *(int *)var2)
{
return(0);
}
else{
return(1);
}
}
int myPrintf(const char * output ,...)
{
va_list arguments;
int stringlength,stringIndx;
char *s;
int d;
char c;
stringlength = strlen(output);
va_start(arguments,output);
for(stringIndx = 0;stringIndx < stringlength;stringIndx++)
{
if(output[stringIndx] == '%')
{
stringIndx++;
switch(output[stringIndx])
{
case 's': /* string */
s = va_arg(arguments, char *);
printf("%s\n", s);
break;
case 'd': /* int */
d = va_arg(arguments, int);
printf("%d\n", d);
break;
case 'c': /* char */
default:
/* need a cast here since va_arg only
takes fully promoted types */
c = (char) va_arg(arguments, char);
printf("%c\n", c);
break;
}
}
else{
printf("%c",output[stringIndx]);
}
}
}
void main()
{
unsigned int au32Nos[10] = {32,44.,55,66,11,8,9,7,9,10};
qsort(au32Nos,10,4,compare);
myPrintf(" %d %d %d %d %d %d %d %d %d %d",au32Nos[0],au32Nos[1],au32Nos[2],au32Nos[3],au32Nos[4],au32Nos[5],au32Nos[6],au32Nos[7],au32Nos[8],au32Nos[9]);
}
Want program for magic square using c?
You have to create 9 empty labels on the gui, then randomize 9#'s. assign each random number to the labels in the 3x3 square. ( you have to keep in your head where each random number will be). Then create a loop that does not end until each row, (labels 1-3), each column (labels 1,4,7), and diagnal ( 1,5,9) are different unique numbers and they add to 15(or the magic number).
-----------
For magic squares with an odd number of rows/columns (i.e. 3x3, 5x5, etc.), there is a simple algorithm to fill the squares. Magic squares with even number of rows/columns do NOT follow this algorithm.
Start in the top row, middle square. Place the number 1 there. The rest of the squares are filled as follows.
Choose the next cell by moving up and to the right. If the square falls outside the squares, the next number goes in the first cell of the row above it. If there is no row above it, drop down to the bottom of the next column and place the number there. If there is no column to the right, drop immediately below and place the number there. If the cell is already filled, drop immediately below and place the number there. Continue until all cells are filled. The number in the middle of the sequence should fall in the middle column of the middle row. The formula for the total of each row/column is: total = n * ((( n * n ) / 2 ) + 0.5)
Samples:
Magic square of 3x3:
8 1 6
3 5 7
4 9 2
Each row/column adds up to: 3 * ((( 3 * 3 ) / 2 ) + 0.5) = 15
-----------------------
Magic square of 5x5:
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
Each row/column adds up to: 5 * ((( 5 * 5 ) / 2 ) + 0.5 ) = 65
This algorithm will work for ALL magic squares with an odd number of rows/columns (where number of rows is the same as the number of columns).
C program code for concatenation of string?
Here You Are :
void String_Concate(char *Arr1, char *Arr2)
{
int r=0;
int c = String_Length(Arr1);
int x,p;
for(int i=0;Arr1[i];i++)
{
if((Arr1[i]== 32)(Arr1[i]=='\0'))
{r= i;
break;}
}
for(x = r,p =0;x<=c + String_Length(Arr2);x++,p++)
{
*(Arr1 + x) = *(Arr2 + p);
}
}
Have A nice Day
When comparing programming languages what is commonly used by all software developers?
There are many factors when it comes to choosing a programming language, primarily dependant upon the expected performance, time and budget. Even before a language is chosen, much time must be spent designing the program and often the design will determine the best language to use. in some cases it may be beneficial to modify an existing language to suit the task at hand, particularly with embedded systems.
Where performance is critical, programmers typically choose assembler, however this is usually limited to a small number of key routines since assembly programming is tedious and error-prone. C is typically used for a lot of low-level programming as C instructions can be mapped 1:1 with assembly. C++ is often used as well, as it allows any combination of low-level programming (including inline assembly), C-style programming and high-level abstraction through object-oriented programming. Indeed, the majority of operating systems, embedded systems and all major application software are written in C++ to some degree. C++ can also be found in areas where it was never specifically intended, such as advanced mathematics and theoretical physics.
Although C++ is a cross-platform language, the source code must be recompiled upon each target platform. To achieve this the code needs to be as generic as possible. In particular, generic audio and graphic libraries can help minimise development costs, but where there are differences between platforms, preprocessor directives can be used to filter the appropriate code in the absence of a generic library.
Where performance is not critical, high-level generic languages such as Java can speed up development times and thus reduce costs. Although Java is a compiled language it compiles to byte code rather than machine code. While the byte code will execute on any machine with a suitable Java Virtual Machine (and is therefore extremely portable), the need for interpretation of the byte code to machine code impacts upon performance compared to an equivalent C++ implementation. This also precludes Java from all low-level software development, including operating system kernels, drivers and embedded systems; it is intended purely for applications development.
Although C++ and Java dominate the bulk of application development, areas such as artificial intelligence often require languages that are better suited to the task, such as Lisp.
How arrays must be handled in c plus plus?
If the array is static it can declared in the structure itself:
struct myArrayTag
{
int num[12]; // array of 12 integers (e.g., 48 bytes).
} myArray;
If it is dynamic then you must use a pointer and allocate the array outside the structure. You should also maintain a variable in the structure to keep track of how many elements the array currently has:
struct myBufferTag
{
int * array; // Pointer to array of integers.
int size; // Size of array (number of elements);
} myBuffer;
All the bitwise operators have the same level of precedence in Java true or false?
False:
highest precedence
& bitwise AND
^ bitwise XOR
| bitwise OR
lowest precedence
What is meant by single array?
A single dimensional array, or one-dimensional array, is a contiguous block of memory that contains one or more elements, each of which can store a single fixed-width value. Since each element is the same length (in bytes), the total memory consumed by the array is equal to the product of the element length and the total number of elements.
One-dimensional arrays can be thought of as being a single row or column of numbered pigeon holes (the elements), such that each hole may contain a single object (a value). The numbers identifying each element are a zero-based incremental subscript, or index number. Thus for an array of n elements, the indexes will be in the range 0 to n-1. Some languages permit the first index to be offset from 0 such that the indexes will be in the range offset to offset+n-1, however this does not alter the actual index which is always zero-based.
Arrays permit random, constant-time access to any element in the array via the element's index. When accessing an element, the return value is a reference to the first memory address of that element. This is achieved through simple pointer arithmetic, such that element i will be found at memory address (i-1) x (size of element) bytes from the start address of the array (hence the index is always zero-based, regardless of any offset that is applied).
The value's stored in the elements must be of the same intrinsic type, but can be variables or constants of any kind, including object references and pointer variables, even pointers to other arrays.
Multi-dimensional arrays are merely an extension of one-dimensional arrays, such that each element contains a reference to another one-dimensional array (each element of which may refer to yet another one-dimensional array, and so on). For instance, a two-dimensional array can be thought of as being pigeon holes arranged in rows and columns, such that every row has the same number of columns, and every column has the same number of rows. A three-dimensional array can be thought of as being a cuboid of pigeon holes. Although it's difficult to imagine a four-dimensional array in a three-dimensional space, the easiest way to think of it is as being a one-dimensional array where each element contains a three-dimensional array. More simply, a series of cuboids arranged in a row or a column.
Multi-dimensional arrays needn't reside in contiguous memory, however each individual one-dimensional array that makes up a multi-dimensional array must itself reside in contiguous memory.
Accessing the individual elements of a multi-dimensional array requires one subscript per dimension. Thus for a cuboid that has 3 rows, 3 columns and 3 tiers, the middle box will be found at zero-based index (1, 1, 1). Again, simple pointer arithmetic is employed to determine the address of the element offset from the starting address of each one-dimensional array.
How do you resolve ambiguity in multiple inheritance?
Use virtual base classes. It is best if the common base class has no member variables and all member methods are pure-virtual. The multiple-inheritance class must provide all the implementation for the pure-virtual methods, even if the direct bass classes also provide their own implementations.
When should use a while loop over a do loop?
Generally speaking a for loop looks like this:
for(Initialization;condition;increment)
{
Do Stuff
}
whereas a while loop looks like this:
while(condition)
{
Do Stuff
}
Before the while loop there should be some initialization and somewhere in the Do Stuff section there should be statements that change the condition. Those statements are analogous to the increment section of the for loop.
What is an essential of Object Oriented Programming?
The 3 essential concepts of Object Oriented Programming are:
What are the functions of a database program?
Function of Database
Indexing
Views
Security
Intergrity
Cocurrency
Backup and Recovery
Desing
Documentation
Update
Query
What is micro and how it is different from c variable name?
A macro is a variable that has a constant value throughout the program whereas a C variable is an identifier whose value can differ from function to function, it can be incremented or decremented whereas the value of a macro remains same .
Write a program for area of square in c?
This smells like homework, so I won't give you any actual code. Rather, I'll give you some pseudo-code for the function that returns the area:
calcarea (decimal width, decimal length)
return width * length
P.S., jeez, it's not that hard to do your homework, is it?
What is use of sorting algorithm?
sorting means arranging a list of numbers or elements in an order (ascending or descending).
There are amny tutorials on the web to do this. I would first look at what I wanted to concentrate on. Do you want to program for the web? games? business? be a hacker?. There are a lot of opportunities out there if one is willing to work. PHP and XML besides a good basis in C++ are good nowadays. Get yourself a good Linux distro like Ubuntu 7.04 or Fedora 7 and start playing around with shells and that will get you into the real programming world. Forget about windoze that old hack will soon wear out. The future is in Linux. Don't just take my word for it. My brother works for IBM (and has been a programmer for over 40 years, goes back to the days of punched cards, if anybody remembers that) and he says the same thing.
What is the difference between c plus plus and perl language?
Borland C++ was the successor to Turbo C++ and primarily included a better debugger. The product was later renamed Borland C++ Builder before Borland divided the company and passed all development systems to their CodeGear subsidiary, which produced CodeGear C++ Builder. However, all CodeGear products are now owned by Embarcadero Technologies, thus Embarcadero C++ Builder is the latest incarnation.
How do you declare an int array?
we define the array is
Array array[]={1,2,3,4,5} this is the integer Array
Array array[]={"apple","banana","carrot","mango"} this is the String Array
Using do while statement write cprogram for factorial number?
The program goes as follows:
#include
#include
void main()
{
int i, j=1;
printf("Enter the value of the integer whose factorial has to be calculated");
scanf("%d",i);
while(j
i = i*(i-1);
i--;
printf("The factorial of the integer is:%d",i);
getch();
}
OTHER METHOD.............
#include
#include
void main()
{
int n,f;
f=1;
printf("Enter the number:\n");
scanf("%d",&n);
while(n>0)
{
printf("%d",n);
f=f*n;
n--;
}
printf("The factorial of the integer is:%d",f);
getch();
}
another method
A very easy method,,,,,,
these is the work of 2nd year high school programming........... CVHS..
#include
int main()
{
char m;
int ans, i, n;
i=0;
m='y';
while((m=='y')(m=='Y'))
{
cout<<"Input a number ";
cin>>n;
if(n==0)
{
ans=1;
cout<<"The factorial of a number is "< } else { ans=1; for(i=1;i<=n;i++) { ans=ans*i; } cout<<"The factorial of a number is "< } cout<<"\n Do you want to continue? (Y/N) "; cin>>m; } return 0; } see,, its very easy!!!! my new mathod #include #include main() { int i,j,div,mod; clrscr(); printf("enter any number = "); scanf("%d",&i); for(j=1;j<=i;j++) { mod=i%j; if(mod==0) { printf("%d*",j); div=i/j; i=div; j=1; } } if(j==i) { printf("%d",i); } getch(); }
Write a c program to find the students details using structure?
#include
When float used and when int used in C programming?
if your calculation involves a decimal point, u must use float, otherwise you can use integer for normal purpose.
for example,
if u want to divide some number, lets say 9/4 then u must use float to get the answer in accurate decimal point , otherwise if u use int there, the answer will be just 2 instead of 2.25
whenever we used an integer in the program we used int. if there is any decimal part in the number then we used float.