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

Why single pass compiler are faster than multi pass compiler?

  1. A one-pass compiler is a compiler that passes through the source code of each compilation unit only once. A multi-pass compiler is a type of compiler that processes the source code or abstract syntax tree of a program several times.
  2. A one-pass compilers is faster than multi-pass compilers
  3. A one-pass compiler has limited scope of passes but multi-pass compiler has wide scope of passes.
  4. Multi-pass compilers are sometimes called wide compilers where as one-pass compiler are sometimes called narrow compiler.
  5. Many programming languages cannot be represented with a single pass compilers, for example Pascal can be implemented with a single pass compiler where as languages like Java require a multi-pass compiler.

What are advantages and disadvantages of union in c language?

A union in C++ is similar to a C-style union in that the members of the union are all mapped to the same memory address. In other words, if you were to unify a long with a char, the char would be mapped to the first byte of the long. However, unlike C unions, C++ unions can be derived from other unions, structs or classes, as well as act as base classes for derived unions, structs and classes.

What are the advantages of dynamic memory allocation over static memory allocation?

Readers who are familiar with the concepts of dynamic memory and pointers may wish to skip to the next section of this chapter. In this one, the general concepts of static and dynamic memory is outlined. How these issues are specifically handled in Modula-2 is not taken up again until after the rest of the preliminary discussions are complete.

The distinction made in this section is based on the timing and manner for the setting aside of memory for the use of a program. Some memory use is predetermined by the compiler and will always be set aside for the program in exactly the same manner at the beginning of every run of a given program. Other memory is obtained by the program at various points during the time it is running. This memory may only be used by the program temporarily and then released for other uses.

What are two functions of the CSF?

The functions of the spinal fluid are to cushion or protect the brain from any trauma, provide the necessary nutrients and chemicals to nervous system tissue, and the removal of waste product from the brain. The cerebrospinal fluid is a colorless fluid found in the brain and spinal cord.

How c language is used in real life?

In "real life" as opposed to what?

C is a programming language. It's used to write computer programs. It (and variants, like C++ and C#) are used to write probably the majority of programs in use today.

How can i improve my grammar skill?

Reading books is probably the best way to improve language skills

How sparse matrix can be stored using array?

#include<stdio.h>

int main()

{

int a[20],min,max;

int n;

printf("\nEnter the num of elements: ");

scanf("%d",&n);

printf("Enter the elements\n");

for(int i=0;i<n;i++)

{

scanf("%d",&a[i]);

if(i==0)

{

min=max=a[i];

}

if(a[i]<min)

min=a[i];

else if(a[i]>max)

max=a[i];

}

printf("The largest element is %d. The smallest element is %d.", max, min);

}

Write a C program using dynamic memory allocation to subtract two matrices?

The easiest way would be to write a function that accepts two arrays and returns one.

Lets say you are working with two 2-dimensional arrays.

array<int,2>^ SubtractMatrices(int arr1[][2], int arr2[][2]);

void main()

{

int arr1[2][2] = {0,1,2,3};

int arr2[2][2] = {0,1,2,4};

array<int,2>^ newarr;

// array<int^,2>^ newarr[2][2] = SubtractMatrices(arr1, arr2);

}

array<int,2>^ SubtractMatrices(int arr1[][2], int arr2[][2])

{

array<int,2>^ newarr;

//Insert subtraction algorithm here

return newarr;

}

In this scenario you must pass the function 2 matrices, and then return a pointer to a new matrix.

Hmm, still seems to be an error in there with the return type. I'm not sure if that's the correct way to do it, I did this in Visual Studio's managed C++. .

What is the difference between a class method and object in object-oriented C?

Class methods are the member functions that act upon member variables. An object is an instance of a class. C does not support object-oriented programming, but C++ does.

How do you calculate integer data type?

To determine the range of an integer data type you first need to know the size of the integer, in bytes. This is implementation-dependant, so never assume it will always be 4 bytes. On a 64-bit system, it could be 4 or 8.

To accurately determine the size of any datatype, always use the sizeof() operator. If you don't, then you are guaranteed to run into major problems when porting programs between compilers and architectures.

Once you have the size, determining the range is fairly easy. The following program contains two function overloads to determine the range of an int and an unsigned int, using bitwise shift operations. The main function tests both functions, showing the ranges in both decimal and hexadecimal (example output is shown below).

#include <iostream>

#include <iomanip>

size_t GetRange(const int& i, int& iMin, int& iMax )

{

int sizeInBits = sizeof(i) * 8;

iMin = 1;

iMin <<= --sizeInBits;

iMax = 1;

while(--sizeInBits)

{

iMax <<= 1;

iMax |= 1;

}

return(sizeof(i));

}

size_t GetRange(const unsigned int& u, unsigned int& uMin, unsigned int& uMax )

{

unsigned int sizeInBits = sizeof(u) * 8;

uMin = 0;

uMax = 1;

while(--sizeInBits)

{

uMax <<= 1;

uMax |= 1;

}

return(sizeof(u));

}

int main()

{

using namespace std;

const int w=17, z=12;

int x, iMin, iMax;

unsigned int y, uMin, uMax;

size_t iSize=GetRange(x, iMin, iMax);

size_t uSize=GetRange(y, uMin, uMax);

cout<<setw(z)<<"Type"<<setw(w)<<"int (x)"<<setw(w)<<"unsigned int (y)"<<endl;

cout<<setw(z)<<"Size (bytes)"<<setw(w)<<iSize<<setw(w)<<uSize<<endl;

cout<<setbase(10);

cout<<setw(z)<<"Min (dec)"<<setw(w)<<iMin<<setw(w)<<uMin<<endl;

cout<<setw(z)<<"Max (dec)"<<setw(w)<<iMax<<setw(w)<<uMax<<endl;

cout<<setbase(16);

cout<<setw(z)<<"Min (hex)"<<setw(w)<<iMin<<setw(w)<<uMin<<endl;

cout<<setw(z)<<"Max (hex)"<<setw(w)<<iMax<<setw(w)<<uMax<<endl;

cout<<endl<<endl;

return(0);

}

Output:

Typeint (x)unsigned int (y)Size (bytes)44Min (dec)-21474836480Max (dec)21474836474294967295Min (hex)800000000Max (hex)7fffffffffffffff

Note the way signed integers are represented in hexadecimal. It looks odd but the binary representation of -1 in 8-bit notation is 11111111 (FFh), not 10000001 (81h) as you might expect. It makes more sense when you realise 11111111+00000001=00000000 which, in decimal, would be -1+1=0.

What are the Application of tree and graph in data file structures?

Using binary tree, one can create expression trees. The leaves of the expression tree are operands such as constants, variable names and the other node contains the operator (binary operator). this particular tree seems to be binary because all the operators used are binary operators. it is also possible for a node to have one node also, in case when a unary minus operator is used.

we can evaluate an expression tree by applying the operator at the root to the values obtained by recursively evaluating the left and right sub trees.

How do you implement a stack using two queues?

implementing stack using two queues

initially q1 is full and q2 empty

1] transfer elements from q1 to q2 till last element left in q1

2] loop till q2 is not empty

deque element from q2 and again push in q2 till last element is left in q2

transfer this last element in q1

reduce size of q2 by 1

3]finally q1 contains all elements in reverse order as in stack

eg

1]

q1 = 1 2 3 4

q2 =

2]

3 deques till last element left in q1

q1 = 4

q2 = 1 2 3

3]

deque and again queue q2 till last element left

q1 = 4

q2 = 3 1 2

4] deque q2 and queue q1

q1 = 4 3

q2 = 1 2

5] again

deque and queue q2 till last element left

q1= 4 3

q2= 2 1

6] queue q1

q1= 4 3 2

7] queue last element of q2 to q1

q1= 4 3 2 1

Write a program in c to find the area of rectangle using array?

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

float len,bre,area;

clrscr();

printf("\n\n\t\tEnter the length of the rectangle=\t");

scanf("%d",&len);

printf("\n\n\t\tEnter the breadth of the rectangle=\t");

scanf("%d",&bre);

printf("\n\n\t\tArea of the rectangle=\t%3f",area=l*b);

getch();

}

What is the process of binary search?

1. //ALGORITHM:Bin search(a,i,l,x).

2. //given an array a(i,l) of elements in non-decreasing.

3.// order,1<=i<=l,determine wether x is present and

4. //if so,return j such that x=a[j],else return 0.

5. {

6. if(l=i) then

{

if(x=a[i] then return i;

else return 0;

}

else

{

mid=[(i+l)/2]

if(x-a[mid] then return mid

else if(x<a[mid]) then

return Bin search(a,i,mid-1,x)

else return Bin search(a.mid+1,l,x)

}

}

Algorithm for binary search in c?

#include<stdio.h>

#include<conio.h>

void main()

{

int a[6],i,data,pos;

clrscr();

printf("enter the element of the array");

for(i=0;i<6;i++)

{

scanf("%d",&a[i]);

}

printf("enter the data for search");

scanf("%d",&data);

for(i=0;i<6;i++)

{

if(a[i]==data)

{

pos=i+1;

break;} }

if(pos==i+1)

printf("position of the element is %d",pos);

else

printf("this is not element in this array ");

getch();

}

( form giriver bisht (future hacker and networking engineer;; if any problem persist u can call me at this no. .. (dehradun 8439881423 )

What words have struct in them?

Structure, reconstruct, destruction, and construction.

infrastruture obstruct....

instruct, instructor, misconstrue, obsruction, substructure, superstracture, construe, instructive

How many bytes a char pointer takes?

In 32 bit address space it will most likely be 4 bytes, since 8 bits is a byte and 32 bits / 8 bits = 4. In 64 bit address space it should be 8 bytes (64 bits / 8 bits = 8). It is architecture dependent so use the sizeof() function.

What is a start and end symbol in a flowchart?

Start and end symbols, represented as lozenges, ovals or rounded rectangles, usually containing the word "Start" or "End", or another phrase signaling the start or end of a process, such as "submit enquiry" or "receive product".

i am only 11 and i know all this ict work

What are relational and assignment operators?

Is there a specific language that you're after? The list may vary between them, but I'll try to include them all.

= (Equal To - in BASIC)

<> (Not Equal To - in BASIC)

== (Equal Value - Conventional)

=== (Equal Value and Type - No implicit type conversion)

!= (Not Equal - Conventional)

!== (Different Value or Type - No implicit type conversion)

> (Greater Than)

< (Less Than)

>= (Greater Than or Equal To)

<= (Less Than or Equal To)

I believe some languages also use /= as a Not Equal operator.

Explain in detail in a binary tree of n nodes there are n plus 1 null pointers representing children?

Induction:

1. A tree of one node has two NULL-pointers.

2. Whenever you add a node to a tree, you remove one NULL-pointer (from the parent of the new node), and add two (the child's of the new node) in the same time.

What is function overloading in c language of computer?

There is no such thing as function overloading in C; that is a feature of C++. Function overloading allows us to provide two or more implementations of the same function. Typically, we use function overloading so that the same function can cater for different types. For instance, we might provide one implementation that is optimised to handle an integer argument while another is optimised to handle a real argument. We can also use function overloading to provide a common implementation of a function which can then be invoked by overloads that handle the low-level type conversions.