Programming Languages
Ques.1 - You are working on critical mission project, as a part of the project,it is required to write a function in c which accept two co-ordinates(x1,y1) for a given point p, you need to determine which quadrant given point belongs, e.g. (10,15)(both are positive hence it in Quadrant I,where as point(-10,15) in Quadrant II. In all the there are nine possibilities as given below:
I Quadrant,II Quadrant,III Quadrant, IV Quadrant, +X Axis, -ve X Axis, +Y Axis, -Y Axis and Origin(0,0).
Unfortunately compiler on your computer has developed strange behaviour, it can't compile any conditional statements like If........then else,switch.....case, therefore you can't write any conditional statement. It is very urgent that we need to write the function and can't wait for your compiler to get fixed. Write program /function in c or VB which will accept 2 co-ordinates and return one of the 9 possible values given above. Please remember that you can't write any conditional statement in your function/program.
Q2)Why array index is start with 0?
Q3)How to create header file in c?
Ans :
Create a file and save it as .h extension
e.g.
int add(int a,int b)
{
return(a+b);
}
Save as myheader.h
In another program include this header file.
e.g.
#include<stdio.h>
#include"myheader.h"
void main()
{
int no1=30,no2=40,no3;
num3=add(no1,no2);
printf("Addition is =%d",no3);
}
Q4)Find max int value without using conditional stmt?
Ans :
First way :
int max(int a, int b, int c)
{
int m = a;
(m < b) && (m = b); //these are not conditional statements.
(m < c) && (m = c); //these are just boolean expressions.
return m;
}
Another way :
int main() {
printf("%d\n", max(1,2,3));
printf("%d\n", max(2,3,1));
printf("%d\n", max(3,1,2));
return 0;
}
Output :
3
3
3
Q5)What are the different programming approaches?
Ans :
Different programming approches are as follows :
1)Object Oriented Programming.
3)Procedure Oriented Programming.
4)Logical Programming.
5)Functional Programming.
6) Modular Programming.
Q6)What is difference between While and for?
Ans:
While loop is dynamic and it is used when condition is not fixed.
For loop is static and it is used when condition is fixed or previously known.
Q7)Diff. between if condition and switch case?
Q8)How to change strarting point of your program[ main( )]?
Q9)Structure of FILE in c?
Ans :
typedef struct
{short level ;
short token ;
short bsize ;
char fd ;
unsigned flags ;
unsigned char hold ;
unsigned char *buffer ;
unsigned char * curp ;
unsigned istemp;
}FILE ;
Q10)Array declaration in c and c++?
Ans :
There are different type of array in c/c++ :
1. One dimensional
2. Multi dimensional
In our programming, we have done with the statement:
one dimensional
syntax: data type array_name[size];
e.g. int mark[30];
multi dimensional
syntax: data type array_name[size][size];
e.g int stud[5][5];
Q11)why we uses {} in if condition?
Ans :
This is because it would not be useful code. If you have an if-statement without curly braces ({}), only the first line / statement after the if is executed. So if you only declare a local variable, it cannot be used anywhere else.
if(proceed)
{ int i= 0; // variable i can be used here
}
if (proceed)
int i; // i can not be used anywhere as it is a local variable.
Q12)program for 10boxes?
Q13) If we have a Array of int containing age for 10,000 pepole, sort that array with optimised way?
Ans :
Program is as follows :
public class Sort
{
static int a[]=new int[120]; //Creating array which contains fixed 1-120 value.
public static void main(String[] args)
{
int age[]={10,15,17,20,10,13,12,15,15,40}; //Accepting elements.
for(int i=0;i<age.length;i++)
{
int b=age[i];
a[b]=a[b]+1;
}
for(int j=0;j<a.length;j++)
{
int r=a[j];
for(;r>0;r--)
{
System.out.println(j); //For displaying element in ascending order.
}
}
}
}
Q 14) If you have 2 dice and you have to show date from 00-31?
Ans :
Write on dice
Dice 1- 0,1,2,3,4,5
Dice 2- 0,1,2,6,7,8
for displaying 9 rotate number 6.
Parameters for switch are Integer and character.
1)Using Integer
#include<stdio.h>
void main()
{
int n;
printf("\n enter choice");
scanf("%d",&n);
switch(n)
{
case 1:
printf("\n A is greater");
break;
case 2:
printf("\n B is greater");
break;
default:
printf("\n both are same");
exit(0);
}
} 2)Using Character
#include<stdio.h>
void main()
{
char c;
printf("\n enter choice");
scanf("%c",&c);
switch(c)
{
case 'a':
printf("\n A is greater");
break;
case 'b':
printf("\n B is greater");
break;
default:
printf("\n both are same");
exit(0);
}
}
Q 15) in switch parameter ?
Q 16) if ,for and while demo program?
Q 17) 30 int array sort it with optimse way condition:u cant declare another array,u cant modify?
Q18)How to change JVM memory in Eclipse?
Ans :
Step to chnage JVM memory in eclips are as follows:
Step1: Select Run / Open Run Dialog
Step 2: select the configuration for launching your application
Step 3: Click the Arguments tab
Step 4: in the box "VM arguments" add something like "-Xmx256M" to give your application 256 MB of memory.
Q 19. what are the different values in garbage collection?
Q 20. What is Shallow Cloning and Deep Cloning?
Ans :
What is Shallow Cloning?
Shallow copy is a bit-wise copy of an object. A new object is
created that has an exact copy of the values in the original object. If any of
the fields of the object are references to other objects, just the reference
addresses are copied i.e., only the memory address is copied.
In this figure, the MainObject1 have fields "field1" of int type, and "ContainObject1" of ContainObject type. When you do a shallow copy of MainObject1, MainObject2 is created with "field3" containing the copied value of "field1" and still pointing to ContainObject1 itself. Observe here and you will find that since field1 is of primitive type, the values of it are copied to field3 but ContainedObject1 is an object, so MainObject2 is still pointing to ContainObject1. So any changes made to ContainObject1 in MainObject1 will reflect in MainObject2.
What is Deep Cloning?
A deep copy copies all fields, and makes copies of dynamically
allocated memory pointed to by the fields. A deep copy occurs when an object is
copied along with the objects to which it refers.
In this figure, the MainObject1 have fields "field1" of int
type, and "ContainObject1" of ContainObject type. When you do a deep
copy of MainObject1, MainObject2 is created with "field3" containing
the copied value of "field1" and "ContainObject2"
containing the copied value of ContainObject1.So any changes made to
ContainObject1 in MainObject1 will not reflect in MainObject2.
Q 21. What are the different permutation and combinations of access specifiers?
Ans :
Modifier
|
Class
|
Class Variables
|
Methods
|
Method Variables
|
public
|
ü
|
ü
|
ü
|
|
private
|
|
ü
|
ü
|
|
protected
|
|
ü
|
ü
|
|
default
|
ü
|
ü
|
ü
|
|
final
|
ü
|
ü
|
ü
|
ü
|
abstract
|
ü
|
|
ü
|
|
static
|
ü
|
ü
|
ü
|
|
Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing. JAVA Course in Chennai
ReplyDelete
ReplyDeleteThe information you have posted here is really useful and interesting too & here, I had a chance to gather some useful tactics in programming, thanks for sharing and I have an expectation about your future blogs keep your updates please. from PHP Training Institute in Chennai