In Java, literal character strings such as "foo" are implemented as instances of the String class. These strings are constant and can not be modified directly. Mutable character strings, or string variables, are implemented as instances of StringBuffer class. It is also possible to work directly with arrays of chars, but String and related classes offer lots of useful methods.
What is the difference between malloc and new other than syntax?
Click on the link to your right for the answer.
Answerboth malloc and new functions are used for dynamic memory allocations and the basic difference is: malloc requires a special "typecasting" when it allocates memory for eg. if the pointer used is the char pointer then after the processor allocates memory then this allocated memory needs to be typecasted to char pointer i.e (char*).but new does not requires any typecasting. Also, free is the keyword used to free the memory while using malloc and delete the keyword to free memory while using new, otherwise this will lead the memory leak. AnswerBesides the basic syntactical difference: malloc is a C function which will allocate the amount of memory you ask and that's it. new is a C++ operator which will allocate memory AND call the constructor of the class for which's object memory is being allocated.Similarily, free is a C function which will free up the memory allocated. but delete is a C++ operator which will free up the allocated memory AND call the destructor of the object.
Answermalloc in a function and new is an operator, and its a good programming practice to use an operator instead of functions, because function itself requires some time to be executed whenever that particular function is called. so the main difference is that we use operators instead of malloc because of the TIME CONSTRAINT. Answer1.malloc requires the type casting during decleration , where as new doesn't needed the type casting during decleration 2. when ever we use new for allocating memory along with this it calls the constructor of the class for which object memory is allocated 3. in case of malloc free is the word used to clear the memory, where as delete is the format used in case of new to free the memory after usage 4. malloc is function, where as new is operator..so the time required for execution is less in case of new (it being a operator) as compared to malloc(it being a function) Answer1. malloc is a function call, while new is an operator. This difference is syntactic; behind the scenes, they both perform pretty much the same work to allocate the memory, and operator new also invokes any required constructors. There is a commonplace urban myth that operators are somehow faster in your code than functions; this is not correct, as any operator (except for mathematical operations that correspond directly to a single machine-code instruction) invocation amounts to a function call in any case. 2. malloc can fail, and returns a NULL pointer if memory is exhausted. Operator new never returns a NULL pointer, but indicates failure by throwing an exception instead. There is also a nothrow() version of operator new, which does return NULL on failure.How do you write a program to find the length of a string?
/* with run-time library */
int len;
char* str;
len = strlen (str);
/* without run-time library */
int mystrlen (const char* str) {
int len;
while (*str != '\0') {
len++;
str++;
}
return len;
}
int len;
char* str;
len = mystrlen(str);
Yes, GC can be considered as a JVM utility that checks the status of memory objects and cleans up all unused memory references so that, this memory can be used by other objects.
What is far and near pointer and how are they used?
It is a matter of the memory model you are using. On old or embedded systems, some memory was outside of the range of a normal pointer. If you have 4 megs of ram you need at least a 22bit pointer to see all of it. But let's say you only have a 16 bit pointer. This means you can only access the first 65K of ram. Odd as it may sound, this was a problem on old computers, and is sometimes an issue on embedded devices with limited processing power. The near and far classifications were a solution. Pointers are near by default. In my example above, the 65K of ram would be accessed with a near pointer. To get past that 16 bit limit, you need a far pointer. Thus: memory within the pointer's range is near. Memory outside of the range is far. Near pointer: char near * ptr; Far pointer: char far * ptr;
A far pointer uses both the segment and the offset address to point to a location in memory. A near pointer in contrast uses only the offset address and the default segment. The far pointer can point to any location in memory, whereas the near pointer can only point to a nearby local address.
Something that was important 20 years ago. Now you can forget it.
How many operators are there in C Language?
There are several operators in the C programming language, which are used to perform various operations on variables and values.
Here is a list of some of the most commonly used operators in C:
Arithmetic operators: +, -, *, /, % (addition, subtraction, multiplication, division, modulus)
Assignment operators: =, +=, -=, *=, /=, %=, &=, |=, ^=, =
Comparison operators: ==, !=, , = (equal to, not equal to, less than, greater than, less than or equal to, greater than or equal to)
Logical operators: && (AND), || (OR), ! (NOT)
Bitwise operators: &, |, ^ (AND, OR, XOR)
Increment and decrement operators: ++ (increment), -- (decrement)
Conditional operator: ?: (ternary operator)
It's important to note that there may be some additional operators depending on the specific C compiler or implementation being used.
Explain how memory is represented in a linked list data structure?
Type your answer here... Let lists be a linked. Then list will be maintained in memory unless otherwise specified or implied as follows. First of all list required two liner array we will call them here INFO and LINK such that INFO[K] and LINK[K] contain, respectively, the information part and the next pointer filed of a node of list.
As noted above list also required a variable name such as start which will contain the location of the beginning of the lists and the next pointer sentinel denoted as null which indicates the end of the lists
Since the subscripts of the array INFO and LINK will usually be positive, we will chose null otherwise started.
Which produces faster program execution a compiler or pure interpreter?
A compiled program would execute faster than an interpreter running the same code step by step.
Why return type is not considered while overloading a function?
YES only if: The return type in the child class is a sub-type of the return type of the parent class.
Ex:
public int getName() {} - Parent class method
public String getName() {} - Child class method
If we implement the above two methods in the class hierarchy we will get compilation errors. whereas if we try the below implementation it will work:
public Object getName() {} - Parent class method
public String getName() {} - Child class method
This is because String is a sub-type of Object and hence it works.
This is also called as Covariant Overriding.
Note: This feature is available only from Java 1.5. Earlier versions of Java expect overriding methods to have exactly the same return type as the super class method.
Write a program in'C' language for the implementation of a Stack?
c program for implement a stack using two queue First push the given elements in stack1... then pop those elements and push them in 2nd stack... now pop the elements from this stack... thus implemented queue
Difference Between Variable And constant?
A constant and variable are variations of data types.
int a;
is a variable and its value can be changed by the program as the program runs.
const int b;
is a constant with a fixed value and will have its value set and may not be changed by the program as as the program runs.
All data types may be declared as a constant.
Variable Value Can Be Changed By You In Programme.
What are the two types of comments in c programming language and how do they differ?
C uses two types of comment: single-line and multi-line. The multi-line comment originated in C while the single-line comment originated in C++. Both types are supported by both languages today.
A single-line comment begins with the double-slash token (//) and extends to the end of the line.
A multi-line comment begins with the slash-asterisk token (/*) and ends with the asterisk-slash token (*/).
Examples:
int x; // this is a single-line comment
/* this is multi-line comment, typically
used to introduce a function or class */
Note that since multi-line comments are fully-delimited, they may be used within the middle of a line of code. This is most useful when a function is forward-declared with a default value for one of its arguments and you wish to include that default value in the function definition (something which is not permitted under the one-definition rule):
void f (int = 0); // declaration
void f (int x /* = 0 */) { // definition
}
Such usage is really only of use to the function maintainer, as a reminder that the function has a default value.
We can also use this technique when a function has an argument that is reserved for future use, but is otherwise unused in the current version of the function:
void g (int); // declaration
void g (int /* unused */) { // definition
}
Again, such usage is only of use to the function maintainer.
If you are calling by reference it means that compilator will not create a local copy of the variable which you are referencing to. It will get access to the memory where the variable saved. When you are doing any operations with a referenced variable you can change the value of the variable.
It is a technique whereby the called function receives values from its calling function, stores these values in its local arguments and returns a result. The called function does not have access to any local variables in the calling function. Anything passed into the function call is unchanged in the caller's scope when the function returns.
No, C uses call-by-value. Of course you may use pointers as parameters.
What are the ranges of basic datatype of C' programming languages?
Basic built-in data types in the C programming language are scalar types in variations of char, int and float:
char, unsigned char, signed char
int, signed int, unsigned int, short, signed and unsigned short, long, signed and unsigned long
float, double
Named enumerations are supported. These are weakly typed constant literals of type int. Bitfields are supported as range-limited signed or unsigned integers. Neither qualify as a type in their own right.
Some dialects also support additional types, such as wide character, extra large integers or floating point scalars.
The language also knows a related keyword void, which is used to express the fact that the related item has no known or no specific type. void in itself is not a type (it is rather the absence of a type).
The C programming language also supports three basic aggregates: structure, union and arrays.
Pointers can reference any of the scalar built-ins, enumerations, structures, unions, arrays, and the infamous void. Pointers are viewed as a data type by many.
Other members of the C family of languages also support class and interface types and strongly typed enumerations.
What is the disadvantage of array in c?
Disadvantages of C are:
1. There is no runtime checking.
2. There is no strict type checking (for ex:we can pass an integer value for the floating data type).
3. As the program extends it is very difficult to fix the bugs.
C is a middle level language so it can be used for interaction with the hardware easily, at the same time it can interact with the user...
It uses the POP (Procedure Oriented Programming) approach which is its major disadvantage..
Advantages include its interaction with hardware, easy to learn, code is secure
Compact and efficient. Many people find it rather very difficult to work with.
Another opinion:I do not think C has any disadvantages but others think differently. The correct answer that you need is the answer your teacher wants, ask your teacher or read your text book.Another answer:
C has been made by real programmers, for real programmes. Just like UNIX. If you think that C (or unix) is not your cup of tea, then most likely you are right -- don't try to force.
How to write a program to print 1 2 3... series in C?
main(){
int temp,prev,i;
for(i=2,prev=1;prev<=256;i++){
printf("%d ",prev);
temp=i;
i=i*prev;
prev=temp;
}
}
How is the C programming language not object-oriented?
A "pure object oriented language" is one where every thing in it is treated on a consistent basis as on object, including elementary data types such as an integer. Since C++ treats elementary objects differently than classes, it does not meet the formal definition as a "pure ...".
Why is it necessary to flame the loop between cultures?
because when we inoculate the culture with wire loop,some organism may be sticked to it which may be harmful or can cause trouble.so to destroy the remaining organisms wire loop is flamed again.
A source program is the program written in which language?
It is programming that is licensed in such a way that it provides the source code for everyone to view and suggest changes to, and is usually at no cost or a very lost cost to anyone that wants the program and its source code.
Difference between reference variable and instance variable?
An object is the actual storage space in memory in which some collection of data resides.
A reference variable is a variable which refers to the memory location of an object.
Look at the pseudocode below:
Object obj = new Object();
Here obj is the reference variable, and the data to which it refers is the object.
What is auto declaration in C?
Auto is one of the four storage classes in c. This is the default storage class. The auto storage class can be used only inside functions, i.e. only to declare local variables and not to declare global variables. All the local variables are by default auto variables.
Other storage classes are:
Register - variables declared may get stored in CPU registers instead of RAM
Static - default storage class for global variables
extern - defines global variables that is visible to all object modules
How you can add a user define function in c library?
user defined functions r d functions whch user declare before the main functn in c program...
for eg.
double min( doub;le x,double y);
int factorial( ,)
int square(int)
etc
What is the difference between uninitialized pointer and null pointer in c language?
A null pointer is a pointer that has been initialised with the NULL value (zero). An uninitialised pointer is one that has not be initialised to any value and will in fact store whatever value happened to reside in the pointer's own memory address at the point of instantiation. Uninitialised pointers are a clear sign of bad programming because the only safe way to determine if a pointer is valid or not is to compare its value with NULL. An uninitialised pointer will almost always be non-NULL, which means you run the risk of accessing memory that either does not belong to you, or is otherwise invalid. Most compilers include a debug switch to warn you when you attempt to access any uninitialised variable, which naturally includes pointer variables. This switch must be on at all times.
Whenever you instantiate a pointer, always initialise it straight away, either by nullifying it, or by storing a valid memory address in it. When you are finished with the pointer, it's good practice to nullify it immediately, even if the pointer would subsequently fall from scope. If the pointer is to be immediately re-assigned, there is no need to nullify it (but it's good practice nonetheless). If you follow this practice at all times, you can be assured that any non-NULL pointer will always be pointing at something valid (and if it isn't, then you have some serious problems elsewhere in your code).
As a rule of thumb, if you can use a reference rather than a pointer, use a reference. They are much easier to work with. Pointers should only be used if there's any possibility (however remote) that a reference could be NULL, because a NULL reference will completely invalidate your program (pointers can be NULL, but references can never be NULL). This is why functions such as malloc() and calloc(), and the C++ new operator all return pointers rather than references. You can only return a reference when an allocation is guaranteed to succeed, and a dynamic memory allocation simply cannot make that guarantee.
Need of structured programming?
That basically refers to a programming language that has support for conditional statements (if), code repetition (while, for, ...), and subroutine or function calls. Most modern language have that. The term is also sometimes used for languages that do NOT work with OOP. Actually OOP includes the structured programming concepts mentioned above, but it includes a few other things, too.