What is composite data type in c?
Composite datatypes are the datatypes which can be constructed with in a program by using prmitive datatypes and other composite types.the act of constructing a composite data type is called composition..............
Example: (the words input and amtTotal are variables)
// Determine if the user entered the correct amount
if (!(input >= 25 && input <= 200))
System.out.println("You must enter an amount between 25 and 200");
else
{
System.out.println("Total = $" + amtTotal);
}
Why is programming language named C?
C derives from a programming language called B, that existed before it. Since C was something of a successor to it, to indicate the advancement from B., the language is called C, the next letter.
What is the container object that holds a fixed number of values of single type?
There are multiple answers to this question, but the most basic one common to both Java and C is the array.
An array is a simple structure that you initialize to a certain size and fill with data. Think of an array as a sort of list, where each element in the list is numbered starting from zero up to the list size minus one (or the array is zero-based, as it's also called).
In Java:
// 10 is the number of elements the array can hold
int[] myIntArray = new int[10];
myIntArray[0] = 2; // The first element in the array
myIntArray[9] = 4; // The last element in the array
Referencing myIntArray[10] or higher will cause a runtime error in Java, which may stop your program.
In C:
// 10 is the number of elements the array can hold
int myIntArray[10];
myIntArray[0] = 2; // The first element in the array
myIntArray[9] = 4; // The last element in the array
Referencing myIntArray[10] or higher results in a buffer overflow in C (and C++). Note that in C, this won't throw errors like they do in Java, and this can and very likely will cause your program to have random bugs and possibly even crash from a segmentation fault, so be a bit more careful about using arrays in C.
What does possible loss of precision means?
When Java (or another programming language) warns you that there is a possible loss of precision, they mean that you are trying to treat one type of number as a different type.
For instance, if you try to store an int value in a byte variable:
int i = 10;
byte b = i;
The int can store more information, so forcing it into a byte may cause a loss of that extra information.
In order to work around this, you need to cast the variable to tell the programming language that you really want to convert from one type to the other.
int i = 10;
byte b = (byte) i;
public double getExp(double x)
{
return Math.pow(Math.E, x);
}
Write a program to multiply two polynomials using an array?
#include<stdio.h>
#include<malloc.h>
int* getpoly(int);
void showpoly(int *,int);
int* addpoly(int *,int,int *,int);
int* mulpoly(int *,int,int *,int);
int main(void)
{
int *p1,*p2,*p3,d1,d2,d3;
/*get poly*/
printf("\nEnter the degree of the 1st polynomial:");
scanf("%d",&d1);
p1=getpoly(d1);
printf("\nEnter the degree of the 2nd polynomial:");
scanf("%d",&d2);
p2=getpoly(d2);
printf("Polynomials entered are\n\n");
showpoly(p1,d1);
printf("and\n\n");
showpoly(p2,d2);
/*compute the sum*/
d3=(d1>=d2?d1:d2);
p3=addpoly(p1,d1,p2,d2);
printf("Sum of the polynomials is:\n");
showpoly(p3,d3);
/*compute product*/
p3=mulpoly(p1,d1,p2,d2);
printf("Product of the polynomials is:\n");
showpoly(p3,d1+d2);
}
int* getpoly(int degree)
{
int i,*p;
p=malloc((1+degree)*sizeof(int));
for(i=0;i<=degree;i++)
{
printf("\nEnter coefficient of x^%d:",i);
scanf("%d",(p+i));
}
return(p);
}
void showpoly(int *p,int degree)
{
int i;
for(i=0;i<=degree;i++)
printf("%dx^%d + ",*(p+i),i);
printf("\b\b\b ");
printf("\n");
}
int* addpoly(int *p1,int d1,int *p2,int d2)
{
int i,degree,*p;
degree=(d1>=d2?d1:d2);
p=malloc((1+degree)*sizeof(int));
for (i=0;i<=degree;i++)
if((i>d1) && (i<=d2))
*(p+i)=*(p2+i);
else if((i>d2) && (i<=d1))
*(p+i)=*(p1+i);
else
*(p+i)=*(p1+i)+*(p2+i);
return(p);
}
int* mulpoly(int *p1,int d1,int*p2,int d2)/* this is the function of concern*/
{
int i,j,*p;
p=malloc((1+d1+d2)*sizeof(int));
for(i=0;i<=d1;i++)
for(j=0;j<=d2;j++)
p[i+j]+=p1[i]*p2[j];
return(p);
}
Write a Program for reverse of number using pointer?
void main()
{
int *n,a,r=0;
clrscr();
printf("enter any no to get its reverse: ");
scanf("%d",&*n);
while(*n>=1)
{
a=*n%10;
r=r*10+a;
*n=*n/10;
}
printf("reverse=%d",r);
getch();
}
Output:
enter any no to get its reverse: 456
reverse=654
How do you assign the value 45 to the variable PassMark using High-level programming language?
In C:
int pass_mark;
pass_mark = 45;
In C++:
int pass_mark {45};
Can keyword be used as variables?
No, any keyword could be used as a identifier (a method, class or variable name). These keywords have a special meaning in the language and the compiler can not identify if they are used as a variable name or as a keyword,
Write this expression as a factorial 87654321?
That's not the factorial of any number. For a start, the factorial of any number greater than or equal to 2 is even, because of the factor 2. The factorial of any number greater or equal to five ends with 0.
Another answer:
I suspect the questioner meant to ask how to write 8*7*6*5*4*3*2*1 as a factorial. If so, then the answer is "8!"
How the values stores in HashMap?
values are stored in a bucket in hashmap, if two objects map to same bucket location by hash function then they are stored as same bucket location but in a form of linked list.
An array is:
simply a collection of similar objects
How you create one: (I think)
Basically you receive or copy an image and place it in an array and assign it an mage Areray name.
How you access info and elements
It can be accessed by means of a variable name and an index.
What is the initial value of a numeric variable?
When we talk about instance variables, the default initial value for a numeric variable is always '0'. Any other variable in your code must be initialized before you can use it.
public class MyClass{
public int x; // 0 by default
public float y: // 0 by default
public MyClass{
int z;
z++; // Error 'z' don't have a default value
}
}
If you write int in place of void in public static void main what happand?
If you change the return type (to any type no only int) of your 'main' method the jvm no longer can use this method as a entry point for your program.
It seems to be no errors, but your program do nothing.
When xor and or operation are same exmple A or B or C equals A xor B xor C?
Check the following table:
a b c a+b+c a^b^c
0 0 0 0 0 =
0 0 1 1 1 =
0 1 0 1 1 =
0 1 1 1 0
1 0 0 1 1 =
1 0 1 1 0
1 1 0 1 0
1 1 1 1 1 =
So they are equal if the number of ones between a, b, and c is zero or an odd number.
What is JFM in Java and what is the use of it?
jFM is a java file manager. It is used to access the file system.
Now I haven't done Java in years, but I did a little research and things have changed a bit, but this should work:
import java.util.Random;
Random rand = new Random();
String newNum = "";
for (int i = 0; i < 3; ++i) {
int randNum = rand.nextInt(26)+65;
newNum = newNum + ((char)randNum);
}
for (int i = 0; i < 3; ++i) {
int randDigit = rand.nextInt(10);
newNum = newNum + randDigit;
}
System.out.println("Three Letters, and 3 Numbers: " + newNum + ".");
Which classes are used in java to create client server model?
we use sockets for client server model..
Does Java keywords are written in lowercase as well as uppercase?
it depends
mostly it is written in lower case
but few start with an uppercase
as Java is case sensitive
if single line comment just place // before for single line comment else if multiple line denote as like this /*.............................
..............................*/
Strictly speaking, // is non.standard in C only in C++
Differences between declaring a method and calling a method?
Declaring a method is when you code for what the method will perform. When you call a method, you are using the method you have written in another part of the program, (or inside the method if it is recursive).
Are constructors allowed to have a return statement in them?
NO...The reason being, when you return something, someone is supposed to receive what you are returning...So when the object is not yet created, there wont be any body to receive it.
What are Semantic errors in a programming language?
Semantic or Syntax errors are errors in the way a programmer has written his code. The code does not conform to language standards and is incorrect.
Ex:
for(int i = 0, i++, i<10) {
}
The above is a syntactically incorrect declaration of a for loop in Java. The compiler would not let you compile this code successfully.