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

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.

Write a program in C language to find the ratio of two numbers?

To find the ratio of x and y, the formula is x/GCD(x,y) : y/GCD(x,y).

#include<stdio.h>

#include<conio.h>

int gcdrec(int ,int);

void main()

{

int x,y;

clrscr();

scanf("%d %d",&x,&y);

printf("Ratio = %d:%d",x/gcdrec(x,y),y/gcdrec(x,y));

getch();

}

int gcdrec(int a , int b)

{

return(b!=0 ? gcdrec(b,a%b) :a);

}

Factorial in c program using for loop?

#include<stdio.h>

#include<conio.h>

void main()

{

int i,n,fact=1;

clrscr();

printf("enter the number");

scanf("%d",&n);

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

printf("%d",n);

fact=fact*i;

{

printf("the factorial is=%d",fact);

}

getch();

}

By:-Abhishek Goyal(goyal.abhi40@yahoo.com)

What is the index number of the last element of an array with 9 elements?

(array.length - 1) will find the index of the last element in an array (or -1 if the array is empty).

Is pascal high level language?

The original Pascal programming language was designed by Niklaus Wirth between 1968 and 1969, published in 1970. Object Pascal was developed in 1985 by Larry Tessler, in consultation with Wirth.

What is static function and static class?

Static function are function only visible to other function in same file Function outside the class can access, useful whenever we need to have functions which are accessible even when the class is not instantiated.

What does iteration mean in ict?

i want the answers not to answer it

come on

:(

mas

mildly amused smile=mas

lol

Illustrate to implement deque using circular linked list?

#include <stdio.h>

#include <conio.h>

#include <alloc.h>

struct node

{

int data ;

struct node *link ;

} ;

struct dqueue

{

struct node *front ;

struct node *rear ;

} ;

void initdqueue ( struct dqueue * ) ;

void addqatend ( struct dqueue *, int item ) ;

void addqatbeg ( struct dqueue *, int item ) ;

int delqatbeg ( struct dqueue * ) ;

int delqatend ( struct dqueue * ) ;

void display ( struct dqueue ) ;

int count ( struct dqueue ) ;

void deldqueue ( struct dqueue * ) ;

void main( )

{

struct dqueue dq ;

int i, n ;

clrscr( ) ;

initdqueue ( &dq ) ;

addqatend ( &dq, 11 ) ;

addqatbeg ( &dq, 10 ) ;

addqatend ( &dq, 12 ) ;

addqatbeg ( &dq, 9 ) ;

addqatend ( &dq, 13 ) ;

addqatbeg ( &dq, 8 ) ;

addqatend ( &dq, 14 ) ;

addqatbeg ( &dq, 7 ) ;

display ( dq ) ;

n = count ( dq ) ;

printf ( "\nTotal elements: %d", n ) ;

i = delqatbeg ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

i = delqatbeg ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

i = delqatbeg ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

i = delqatend ( &dq ) ;

printf ( "\nItem extracted = %d", i ) ;

display ( dq ) ;

n = count ( dq ) ;

printf ( "\nElements Left: %d", n ) ;

deldqueue ( &dq ) ;

getch( ) ;

}

/* initializes elements of structure */

void initdqueue ( struct dqueue *p )

{

p -> front = p -> rear = NULL ;

}

/* adds item at the end of dqueue */

void addqatend ( struct dqueue *p, int item )

{

struct node *temp ;

temp = ( struct node * ) malloc ( sizeof ( struct node ) );

temp -> data = item ;

temp -> link = NULL ;

if ( p -> front NULL )

return ;

while ( p -> front != NULL )

{

temp = p -> front ;

p -> front = p -> front -> link ;

free ( temp ) ;

}

}

What does Microsoft Visual C plus plus Runtime Library mean?

The runtime library is a collection of routines that implements basic functionality of the platform. Routines such as I/O, memory control, startup, shutdown, common system functions, etc. are located in the runtime library.