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 have character range -128 to 127?

To let the very first bit (2^7) show the sign of the number: bit=1 means negative (-128..-1), bit=0 means non-negative (0..127)

00H=0

...

7fH=127

80H=-128

...

ffH=-1

What is interrupt in c?

Interrupt handling is performed by the operating system kernel. In the Intel IA-32 platform, for instance, it is handled at Ring-Zero.

C++ code does not normally run in the kernel. It runs in user space, such as in Ring-Three. Unless the operating system allows you to load C++ code in non pageable Ring-Zero space, you cannot write C++ programs to handle interrupts. Even if you could do so, all of the dependencies, such as libraries, would need to also be there, unless you wrote dispatch stubs to transition into and out of Ring-Zero non-pageable space.

That said, you are looking for the Device Driver Kit, or DDK. (In the Windows platform.)

How do you read line by line of a file in c program?

read, fread, fgetc, fgets, fscanf etc... use the help/manual

According to the Gregorian calendar it was Monday on the date 01 01 1900 if any year is input through the keyboard write a c program to find your what is the day on 1st January of this year?

#include <stdio.h>

int main ()

{

int year,days,d;

printf("year?"); scanf("%d",&year);

days = 365*year + (year-1)/4 - (year-1)/100 + (year-1)/400 ;

d=days%7;//to find which day of week

if(d==1)

printf("\n\n\tmonday");

else if(d==2)

printf("\n\n\ttuesday");

else if(d==3)

printf("\n\n\twednesday");

else if(d==4)

printf("\n\n\tthursday");

else if(d==5)

printf("\n\n\tfriday");

else if(d==6)

printf("\n\n\tsaturday");

else if(d==0)

printf("\n\n\tsunday");

return(0);

}

Difference between c syntax and c syntax?

Using normal C you cannot address a bit value.

The minimum you can address is 1 byte.

using embedded C you can access even abit value

C is a widely used general purpose high level programming language mainly intended for system programming

.

Embedded C is an extension to C programming language that provides support for developing efficient programs for embedded devices

.

It is not a part of the C language

How many values can each element in a seven-element array hold?

As many as you like. It ultimately depends on the type of the array. An array of int can obviously only store one integer value per element, however an array of integer arrays would allow us to store two or more integers per element. This is precisely how multi-dimensional arrays are implemented:

int x[4][5];

Here we've declared a 4-element array where each element is an array of 5 integer elements. Thus each element of the "outer" array can hold 5 values in the "inner" arrays. In reality this is just a 20-element array with one integer per element, but because we declared it multi-dimensionally we can refer to each of the 4 "inner" arrays individually as an array in its own right.

Arrays of arrays are useful when dealing with homogeneous types, but if we need to store heterogeneous types we can use an array of structures instead:

typedef struct person_t {

char name[50];

size_t age;

} person;

person x[100];

Here we've declared an array of 100 person objects. But each person object has two member values associated with it; a name and an age:

x[0].name = "Joe Bloggs";

x[0].age = 42;

1 Write a 'c' program to read the age of 100 persons and count the number of persons in the age group 50 to 60.use for loop and continue statements?

main()

{

int age[100],count=0,i;

clrscr();

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

{

printf(" enter the person age %d",i);

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

}

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

{

if(age[i]>=50 && age[i]<=60)

{

++count;

}

}

printf(" no.of persons in the age group 50 to 60 is %d",count);

getch();

}

What is an example of square array?

*SQUARE

definition- A 4-sided regular polygon with all sides equal and all internal angles 90°

example- A computer screen

*SQUARE (SQUARE ROOT)

definition- A divisor of a quantity that when squared gives the quantity

example- The square roots of 25 are 5 and −5 because 5 × 5 = 25 and (−5) × (−5) = 25.

Explanation of top down marketing?

Top down marketing is a branding strategy where country strategies are based upon global branding strategies.

How to write a program in c to find the cude of a number?

You cannot multiply a number (a multiplicand) unless you know what to multiply it by (the multiplier). The result of a multiplication is the product, such that multiplicandtimes multiplier equals product.

In C programming we use the multiplication operator (binary *) to obtain the product of two scalars:

double product (double multiplicand, double multiplier) {

return multiplicand * multiplier;

}

When a function is recursively called all automatic variables are stored in a list stored in a stack stored in an array stored in queue?

Nothing special, try it:

void foo (int frec, int val)

{

. int x= val;

. if (frec) {

. . printf ("before recursion x=%d\n", x);

. . foo (frec-1, val+1);

. . printf ("after recursion x=%d\n", x);

. } else {

. . printf ("in recursion x=%d\n", x);

. }

}

What is an array and how do you use them in c and c plus plus?

#include<iostream>

#include<vector>

int main()

{

std::vector<int> v {1, 4, 8, 15, 23}; // initialise array with 5 elements

v.push_back (42); // add a 6th element

for (auto i : v) std::cout << i << std::endl; // print array elements

}

How do you implement queue using stack in c plus plus?

A queue in any language is a singly-linked list structure that permits new data to be inserted only at the end of a list while existing data can only be extracted from the beginning of the list. Queues are also known as a first in, first out (FIFO) structure. Unlike a standard singly-linked list, the list maintains a pointer to the last node as well as the first, in order to insert new data and extract existing data in constant time.

Variations on the queue include the priority queue which permit data to be weighted, such that data with the greatest priority is promoted to the front of the queue, behind any existing data with the same or higher priority, using an insertion sort technique. Insertion is therefore achieved in linear time rather than constant time, however extraction is always in constant time.

Write a program for addition of to array in c program?

#include
#include
void main()
{ int a[10][10],b[10][10],c[10][10],i,j.r,c;
printf("\nNo. of Rows?");
scanf("%d",&r);
printf("\nNo. of Cols?");
scanf("%d",&c);
printf("\nEnter elements for 1st array:");
for(i=0;ifor(j=0;jscanf("%d",&a[i][j]);
printf("\nEnter elements for 2nd array:");
for(i=0;ifor(j=0;jscanf("%d",&b[i][j]);
for(i=0;ifor(j=0;jc[i][j]=a[i][j]+b[i][j];
printf("\nDisplaying the result:\n");
for(i=0;i{ for(j=0;jprintf("%d",c[i][j]);
}
getch();
}
If the ans helps you,plz increase the trust point.

How can you allocate memory dynamically in c?

char* new_string; // could be any type

new_string = (char*) malloc (5120); // allocate memory - typecast is necessary

if (new_string == NULL) ... memory exception ...

... use the data ...

free (new_string); // release memory when done

How do you reverse the order of words in a sentence in c?

#include <string.h>

char * revsentence(char *str)

{

int i,j,len;

char temp;

len=0;

len=strlen(str)

for(i=0;j=len-1;i<j;i++,j--)

{

temp=str[i];

str[j]=str[i];

str[j]=temp;

}

return str;

}

How do you push and pop stack elements?

algorithm of push

if(top==Max-1)

{

cout<<"\n the stack is full";

}

else

top++;

arr[top]=item;

////////////////////////////////////////

algorithm of pop

if(top==-1)

{

cout<<"\n the stack is empty";

}

else

return arr[top];

top--;

}

Write a c program using dynamic memory allocation to transpose a matrix?

Type your answervoid main()

{

int **a,**b,**c;

//int c[3][3];

int a_r,a_c,b_r,b_c;

int i,j,k;

clrscr();

again:

printf("\nenter rows and columns for matrix one:");

scanf("d",&a_r,&a_c);

printf("\nenter rows and columns for matrix two:");

scanf("d",&b_r,&b_c);

if(a_c!=b_r )

{

printf("\ncan not multiply");

goto again;

}

/* allocate memory for matrix one */

a=(int **) malloc(sizeof(int *),a_r);

for( i=0;i {

a[i]=(int *) malloc(sizeof(int*)*a_c);

}

/* allocate memory for matrix two */

b=(int **) malloc(sizeof(int)*b_r);

for( i=0;i {

b[i]=(int *) malloc(sizeof(int*)*b_c);

}

/* allocate memory for sum matrix */

c=(int **) malloc(sizeof(int *)*a_r);

for( i=0;i {

c[i]=(int *) malloc(sizeof(int)*b_c);

}

printf("\n enter matrix one %d by %d\n",a_r,a_c);

for(i=0;i {

for(j=0;j {

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

}

}

printf("\n enter matrix two %d by %d\n",b_r,b_c);

for(i=0;i {

for(j=0;j {

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

}

}

/*initialize product matrix */

for(i=0;i {

for(j=0;j {

c[i][j]=0;

}

}

/* multiply matrix one and matrix two */

for(i=0;i {

for(j=0;j {

for(k=0;k {

c[i][j]=c[i][j]+a[i][k]*b[k][j];

}

}

}

/* display result */

printf("\n Product of matrix one and two is\n");

for(i=0;i {

for(j=0;j {

printf("%d\t",c[i][j]);

}

printf("\n");

}

/*free memory*/

for(i=0;i {

free(a[i]);

}

free(a);

for(i=0;i {

free(b[i]);

}

free(b);

for(i=0;i {

free(c[i]);

}

free(c);

printf("\npress any key");

getch();

}

I would suggest you go to

http://code.freefeast.info/matrix-multiplication-using-pointers-in-c-dynamic-matrix-multiplication-in-c/

It has got a well formatted and commented code for this problem

Write a C program to calculate the sum of squares of numbers from 1 to N?

#include <iostream>

using namespace std;

int main()

{

int i,sum; // variables

sum = 0; // initialize sum

/* recursive addition of squares */

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

sum = sum + (i * i);

cout << sum <<" is the sum of the first 30 squares."

<< endl;

return 0;

}

Does every programming language have a compiler?

Operating systems (OSs) are precompiled into low-level executable code that can operate efficiently. An OS distribution might include one or more language compilers, but they aren't needed to run the OS.

High-level programming language intepreted?

EZtrieve and EZtrieve Plus are examples of a high level language that can be either compiled or run interpretive.

What is recursion in c explain with the help of an example?

Recursion is the technique of a function calling itself, rather than iterating through the use of loops. The classic example of a recursive function is the computation of N Factorial...

int nfact (int n) if (n 5, for instance, it will call itself an additional 3 times, so you will have 4 stack frames where the local value of n is 5, 4, 3, and 2. When you get to the last call, you unwind the stack frames, and the multiplication of 2, 3, 4, and 5 takes place.

This example is for illustration only. It fails miserably with even small values of n (13, using 32-bit arithmetic) due to integer overflow, because N Factorial get large quickly.

How does a 'string' type string differ from a c-type string?

A char is a single character. A String is a collection of characters. It may be empty (zero characters), have one character, two character, or many characters - even a fairly long text.

The single quote (') is used to deliniate a character during assignment:

char someChar = 'a';

The double quote (") is used to delineate a string during assignment:

String someString = new String("hello there");

Note that char is a primitive data type in Java, while String is an Object. You CANNOT directly assign a char to a String (or vice versa). There is, however, a Character object that wraps the char primitive type, and Java allows method calls to be made on the char primitive (automagically converting the char to Character before doing so).

i.e. these ALL FAIL:

someString = SomeChar;

someString = new String(someChar);

However, these WILL work:

someString = Character.toString(someChar);

someString = someChar.toString();

Also note that a String is a static memory allocation, while a character's is dynamic. By that, I mean that when a String is created, it is allocated a memory location exactly big enough to fit the assigned string. Any change to that String forces and entirely new memory location to be allocated, the contents of the old String copied in (with the appropriate changes), and the old String object subject to garbage collection. Thus, making changes to a String object are quite inefficient (if you want that kind of behaviour, use StringBuffer instead).

A character is allocated but once; all subsequent changes to a character variable simply overwrite that same memory location, so frequent changes to a character variable incur no real penalty.

Distinguish Between Static and Dynamic variable in C programming?

Global (file scope) variable and static global variables both retain their value for the duration of the program's execution. Static global variables are visible only to functions within the file they are declared, while global variables are visible to all compilation units (files) within the linked load module.