What is the relationship between the value of the subscript and the value of the array element in c?
You can access the array-element via index (or subscript), but it is not possible the other way around.
Can an short value be assigned to int variable?
Yes, but you may cause truncation error because the short variable does not necessarily have the same range as an int variable. Most modern compilers will flag this as a warning. If you know that the value of the int variable will not exceed the range of a short variable, you can explicitly prevent the warning with a typecast, i.e. someShort = (short) someInt; and the compiler will assume that you know what you are doing.
C program to check whether the number and its reverse are same or not?
#include <stdio.h>
#include<conio.h>
void main ()
{
int a,r,n,sum=0;
clrscr();
printf("enter the number");
scanf("%d",& n);
c=n
while (n!=0)
{
a=n%10;
n=n/10;
sum=sum*a+a
}
printf("the reverse is %d \n",sum);
if(c==sum)
printf("\n the given number is palindrome");
else
printf("\n the given number is not a palindrome");
getch();
}
#include
#include
#include
int main(int argc, char *argv[]){
int n, smallest, largest, sum, temp;
if(argc < 2){
printf("Syntax: foo val1[val2 [val3 [...]]]\n");
exit(1);
}
smallest = largest = sum = atoi(argv[1]);
for(n = 2; n < argc; n++){
temp = atoi(argv[n]);
if(temp < smallest) smallest = temp;
if(temp > largest) largest = temp;
sum += temp;
}
printf("Smallest: %i\nLargest: %i\nAverage: %i\n", smallest, largest, sum / (argc - 1));
return 0;
}
Why the format specifiers are not used in cpp?
You might be wrong: printf and scanf are usable in C++ just as in C. With format specifiers.
Will a type cast allow you to convert a double to int without data loss?
No. Not unless the value contained is an integer value, and the number of digits is less than the resolution of the int type. Most doubles support about 15 digits of resolution, while 32 bit integers only support 9. You might be successful in a 64 bit int format, but you still need to consider the maximum value.
The only thing the type cast buys you is elimination of the compiler warning. With the type cast, you are telling the compiler that you know what you are doing.
What is noun verb analysis in object oriented analysis and design?
Noun-verb analysis is a means of identifying classes and their methods. If you look in the "problem statement" (a statement that explains what a software application should do) for nouns, they will often wind up as classes. If you look for verbs, they will be methods of those classes.
A simple example of a problem statement might be:
We are a training facility. We need to be able to track the classes that students take. Classes are taught by teachers. Students enroll in classes. Each class is assigned to one teacher and one classroom.
So, we have classes, students, teachers and classrooms. Class will have methods like AssignTeacher and AssignClassroom. Students will have Enroll. Of course, there is more, such as how to handle the time of each class, and so on. But this gives an idea.
Why you use printf in c programs not only print?
That is short for "print formatted"; it lets you include format codes to control the output.
A function's declaration must be visible within every translation unit that uses that function, thus multiple declarations are permitted. To ensure consistency across all translation units that use a function, the declaration is usually placed in a header which can be included wherever it is needed. Formal arguments need not be named in a declaration (they do not form part of the function's prototype), but named arguments can provide better documentation and need not match the names used by the definition, or indeed by any other declaration of the same function.
Note that a definition is itself a declaration, thus if a function is declared (but not yet defined), there has to be at least two declarations because the function must be defined somewhere.
The "one definition rule" (ODR) implies there can only ever be one definition of a function, however multiple definitions are permitted provided those definitions appear in different translation units and are token-for-token identical (including the names of formal arguments). Being token-for-token identical means there is only one definition.
Thus the correct answer is D: multiple declarations with one definition.
Without using mod operator find the even or odd?
import java.util.*;
class Demo
{
public static void main(String args[])
{
System.out.println("Even Numbers Are ");
for (int i=1;i<=20;i++)
{
System.out.print(" "+(2*i));
}
System.out.println("\n \n Odd Numbers Are ");
for(int j=0;j<=20;j++)
{
System.out.print(" "+((2*j)+1));
}
}
}
quite a low level view required ......everything stored in memmory is in form of bits (i.e. a sequence of 01). It dependes upon how you are going to read a value. Same sequence of bits can give you different values..try printing x=10; printf("%c %d",x,x);
How do you get the previous value of x (5)? If you didn't store the value in another variable before overwriting it with 2, then you can't. The old value is overwritten and cannot be recovered. In a union, it's possible that you might overwrite only part of a previous value if you store a value to a smaller data type. For example:
union { long a; short b; } c;
c.a = 5;
c.b = 2;
It's possible that you can recover some of the old data of c.a, but for most practical purposes that value would be garbage (and it really depends on the exact alignment of the variables and byte endianness).
What are the commonly used input output functions in C?
Commonly used input/out functions in C are:
* printf( )
* scanf( )
scanf() it is the standard input functions. It is used to get the data from the input devices, which is by default a keyboard, at run time, or execution time. Its general format is:
scanf("one or more format specifier",& one or more variables separated by comma);
For example:
scanf("%d",&a);
scanf("%d%,&a,&b);
printf() It is the standard output functions it is used to show the data to an output device, which is by default a monitor screen, at run time, or execution time. Its general format is:
In case of displaying the message:
printf("Type the message here");
for example:
printf("Hello World");
In case of printing the value:
printf("one or more format specifier", & one or more variables separated by comma);
for example:
scanf("%d",&a);
scanf("%d%f",&a,&b);
How do you install kernel header files?
OS/distribution dependent, for debian: apt-get install linux-kernel-headers
Or you can download the whole kernel-source, which contains the headers as well.
Write a c program to sort the elements of the matrix in ascending order?
#include<stdio.h>
main()
{
printf("Enter Order Of The Matrix\n");
int l,m;
int i,j,k,t,x;
scanf("%d%d",&l,&m);
int a[l][m],temp[l*m];
printf("Enter The Elements Row Wise...\n");
for(i=0;i<l;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Matrix A \n ");
for(i=0;i<l;i++)
{
printf("\n");
for(j=0;j<m;j++)
{
printf("%d\t",a[i][j]);
}
}
/*----------------------------------------------------------------------*/
x=0;
for(i=0;i<l;i++)
{
for(j=0;j<m;j++)
{
temp[x]=a[i][j];
x++;
}
}
for(i=0;i<l*m;i++)
{
for(j=0;j<(l*m)-1;j++)
{
if(temp[j]>temp[j+1])
{
t=temp[j];
temp[j]=temp[j+1];
temp[j+1]=t;
}
}
}
x=0;
for(i=0;i<l;i++)
{
for(j=0;j<m;j++)
{
a[i][j]=temp[x];
x++;
}
}
printf("\nMatrix A After Sort \n ");
for(i=0;i<l;i++)
{
printf("\n");
for(j=0;j<m;j++)
{
printf("%d\t",a[i][j]);
}
}
}
Write a c program to find the maximum value of 25 element in an array?
int findMax(int *array)
{
int max = array[0];
for(int i = 1; i < array.length(); i++)
{
if(array[i] > max)
max = array[i]
}
return max;
}
What is the main function of access?
access is a handy way to see see if a file exist and also if (you are not using a DOS compiler) you have read or write permissions to the file.
C code for linear programming problem?
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int first,last,flag=1;
char str[100];
clrscr();
printf("Enter number to get to check wheather palindrome or not");
gets(str);
first=0;
last=strlen(str)-1;
printf("%d",first);
printf("%d",last);
while(first<=last)
{
if(str[first]!=str[last])
flag=0;
first++;
last--;
}
if(flag==1)
{
clrscr();
printf("this is palindrome");
getch();
}
else
{
clrscr();
printf("sorry this is not a palindrome");
getch();
}
}
What is the significance of asmlinkage modifier in C?
The asmlinkage tag tells gcc that that the function should not expect to find any of its arguments in registers (a common optimization), but only on the CPU's stack. Many kernel functions use the fact, that system_call consumes its first argument, the system call number, and leaves other arguments (which were passed to it in registers) on the stack. All system calls are marked with the asmlinkage tag, so they all look to the stack for arguments.
What are the features differentiate java from c plus plus and c?
Java compiles to byte code suitable for interpretation by the Java virtual machine, whereas C and C++ both compile to native machine code. Thus C and C++ programs perform better than equivalent Java programs. However, Java programs can run on any machine with a suitable Java virtual machine implementation, which is pretty much everything these days. C and C++ programs must be compiled separately upon each supported platform, provided the source code is either generic or includes compiler directives to filter the platform-specific code. Java programs need only be compiled once, thus cross-platform development is greatly simplified, at the cost of performance.
C and Java cannot really be compared since C does not support object-oriented programming concepts. C++ is object-oriented but, unlike Java, it is not 100% object-oriented as it supports the concept of primitive data types that it inherited from C. Java is more closely related to C#, which is 100% object oriented.