answersLogoWhite

0

📱

C Programming

Questions related to the C Computer Programming Language. This ranges all the way from K&R to the most recent ANSI incarnations. C has become one of the most popular languages today, and has been used to write all sorts of things for nearly all of the modern operating systems and applications. It it a good compromise between speed, power, and complexity.

9,649 Questions

Are pointers integers?

A pointer holds a memory address, from 0 to the upper limit of your memory (in 32 bit addressing this is up to 2^32, 64 bit is up to 2^64 bytes). So in math terms, a pointer could be considered a non-negative integer.

However this is not the same as the integer type used in C and other languages, which refers to how the data at that memory address (the raw bits) is interpreted by the system.

So the expression "int *x;" declares a pointer to an integer, but x is a memory address, not a literal C-style integer. The value pointed to by x, however, will be interpreted as a literal C-style integer.

It may be easier to see using a pointer to a char:

char character = 'C';

char *pointerToCharacter = character;

In this case, character is a standard char variable, and pointerToCharacter is a pointer (which is a memory address) that points to the location in memory of a character.

Write C a program to print examination results of 10 students in tabular formatThis includes total average pass or fail and class obtained?

#include<stdio.h>

#include<conio.h>

voidmain()

{

char n[10] ,total;

float a,b,c,d,e,average;

printf("enter marks of five subject");

scanf("%f%f%f%f%f",&a,&b,&c,&d,&e);

if(a>35&&b>35&&c>35&&d>35&&e>35)

printf("congratulation you have passed");

average=total%5

if(average>75)

printf(" %f is distictiona",average);

else

if(average>60)

printf("%f=first devision",average);

else

if(averagea>45)

printf("%f=second devision",average);

else

printf("third devisiona");

getcha();

}

Algorithm for addition of two polynomials using linked list?

Let p and q be the two polynomials represented by the linked list. 1. while p and q are not null, repeat step 2. 2. If powers of the two terms ate equal then if the terms do not cancel then insert the sum of the terms into the sum Polynomial Advance p Advance q Else if the power of the first polynomial> power of second Then insert the term from first polynomial into sum polynomial Advance p Else insert the term from second polynomial into sum polynomial Advance q 3. copy the remaining terms from the non empty polynomial into the sum polynomial.

Write a program in 8086 assembly language that accept a string from the keyboard and then reverses a string using stack The string can be assumed to be available in the data segment The results are?

Mov ax @ data ; ax is initialized with data

mov ds ax ; ax is moved into ds

mov cx 0005h ; cx is initialized to 5

lea si a1 ; si is having lead e.a of a1

lea di a2; di is having lead e.a of a2

add si 0004

again: mov al[si]

mov [di]al ; al is moved into di

dec si

inc di

loop again

int 3 ; interrupt

end

Explain the passing parameters as function in Call by Value and Call by Reference and then distinguish between them?

Call by value essentially passes a copy of an object's value whereas call by reference essentially passes the object itself. Pass by reference is the preferred method whenever possible as call by value will automatically invoke the object's copy constructor, which is often unnecessary, especially if the object is not affected by the function call (pass by constant reference).

What is time complexity to delete a node in singly linked list?

Time complexity to locate a node in a list of n nodes is O(1) at best (first node), O(n) at worst (last node) and O(n/2) on average. Once located, deleting a node takes constant time O(1).

What are showing statements in grammar?

In writing, there is a difference between telling statements and showing statements. A telling statement states a fact, such as that it was cold. A showing statement would illustrate that by, for example, describing how everyone was shivering.

What is a peripheral graphic array?

its no big deal, nobody should be worrying about relationships in elementy school anyway, there kids. they dont know better,

What is field data type?

The data type of the Variable determines/indicates the type of data that can be stored in a field/variable

How do you calculate 2s complement of an integer?

Two's complement is the normal implementation of signed integers, so just take the negative.

int a = 123;

int b = -a; /* b now equals -123 */

The actual implementation of two's complement notation is that, to make something negative, simply invert the bits and then add 1.

12310 = 00000000011110112 (using 16 bit notation)

Invert and you get 111111111000100. Add one and you get 111111111000101, so...

-12310 = 1111111110001012

Write a program to find a substring in a given string in c?

#include<stdio.h>

#include<conio.h>

int main()

{

int i=0,j=0,k=0,count=0,l=0,k1=0;

char a[80],b[80];

clrscr();

printf("\nEnter main string:-\n");

gets(a);

printf("\nEnter sub-string:-\n");

gets(b);

l=strlen(b);

while (a[i]!=EOF)

{

if (a[i]==b[j])

{

i++;

j++;

k1=1;

if (j==l)

{

j=0;

k=1;

count=count+1;

}

}

else

{

if (k1==1)

{

j=0;

k1=0;

}

else

i++;

}

}

if (k==1)

{

printf("\n\nThe given sub-string is present in the main string.");

printf("\nIt is present %d times.",count);

}

else

{

if (k==0)

printf("\n\nThe given sub-string is not present in the main string.");

}

}

C program for worst fit algorithm?

#include<iostream.h>

#include<conio.h>

#include<string.h>

int main()

{

unsigned int n,j,i,size[10],m,x=0,t;

int cho=1,ch;

system("cls");

cout<<"\t\t STORAGE PLACEMENT STRATEGIES\n";

cout<<"\tEnter the number of holes:";

cin>>n;

for(i=1;i<=n;i++)

{

cout<<"\n Enter The Size Of Hole "<<i<<":";

cin>>size[i];

}

while(cho==1)

{

cout<<"\nEnter the size of the incoming program:";

cin>>m;

cout<<"\nMenu";

cout<<"\n1.First Fit Strategy \n2.Best Fit Strategy";

cout<<"\n Enter your choice:";

cin>>ch;

x=0;

switch(ch)

{

case 1:

for(i=1;i<=n;i++)

{

if(size[i]>=m)

{

cout<<"\nYour program is placed in hole "<<i;

size[i]-=m;

x=i;

break;

}

}

if(x==0)

cout<<"There is no room for your program.";

break;

case 2:

unsigned int temp=0,pos=0,t1;

if(m<=size[1])

{

temp=size[1]-m;

pos=1;

}

else

temp=size[1];

for(i=2;i<=n;i++)

{

if(m<=size[i])

{

t1=size[i]-m;

if(temp>=t1)

{

temp=t1;

pos=i;

}

}

else temp=size[i];

}

if(pos==0)

cout<<"There is no room for your page.";

else

{

size[pos]=size[pos]-m;

cout<<"Your program is palced in hole "<<pos;

}

break;

case 4:

return;

}

cout<<"\nFree Storage List";

for(i=1;i<=n;i++)

cout<<"\nHole "<<i<<"\t\t"<<size[i];

cout<<"\n\nPress 1 to continue:";

cin>>cho;

}

}

Why do we use double in java but do not use float?

Double is more precise than float. The 4 bytes saved on a float are usually not very relevant. However, if you need to save large amounts of numbers (e.g. in an array), and you don't need the extra precision, you might save some memory by using float.

What is a structure variable in computer programming?

A structure variable is a name that refers to a data structure. For example:

struct S {/*...*/};

int main (void) {

S x; /* x is a structure variable that refers to an instance of the structure S */

// use x...

return 0;

}

What is the perror function used for in C programming?

The perror() function is used to print a user-defined error message to stderr. Consider the following:

Example:

#include

int main ()

{

FILE * pFile;

pFile=fopen ("missing.txt","rb");

if (pFile==NULL)

perror ("missing.txt");

else

fclose (pFile);

return 0;

}

Possible Output:

missing.txt: No such file or directory

We can achieve the exact same effect with a more verbose fprintf() statement, such that the following are equivalent:

perror ("Error");

fprintf (stderr, "Error: %s\n", strerror (errno));

The following are also equivalent:

perror (NULL);

fprintf (stderr, strerror (errno));

We typically use fprintf() statement when we need to print messages other than those provided by strerror and/or wish to redirect the output to a device other than stderr. But for all error messages based upon the thread-local errno, perror is more concise and reduces the chances of introducing errors through typos (such as accidently redirecting errors to stdout instead of stderr).