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

Getting source code of c?

C is a programming language, so it doesn't have source code.

(On the other hand, C compilers do have source code, but you, as a beginner in programming, could not understand them.)

How do you point to the first node in a linked list?

The list itself should maintain a pointer to the first node in the list. If it is NULL, the list is empty.

When do we use an address operator in c'?

In C we use & operator while giving address of some variable to some pointer variable. & operator is also used in scanf().

What is meant by inheritance?

In computer programming, inheritance means to derive a new object from an existing object, such that the new object inherits all the properties of the existing object. In object oriented programming, derived classes inherit the public and protected members of their base classes. This allows new classes to be created from existing classes, without the need to duplicate large chunks of code in the existing class. The new class can augment the inherited code to provide more specific behaviour.

How can the pointer speed up program execution?

It is not that simple. Obviously, sub-optimal programs can be optimized, which may or may not include using pointers, but it requires a skilled programmer.

How do you find the no of characters and numerics in the given string?

First of all numbers are not meant to be stored in a string and if u do so in C, these numbers will be treated as characters and you can not perform any calculation on these numbers, and to find the number of characters in a string use the strlen() from the string.h file.

What is the difference between declaration and initialization?

Perhaps an example will help.

extern int value; /* declaration */

int value; /* definition */

int value= 20; /* definition with initialization */

Why keyword cannot be used as an identifier in c language?

It's by design; this way the lexical parser is able to decide that any given string is a keyword or an identifier.

Is there any chance a computer that convert the program into machine language is called as a interpreter?

No. Computers do not convert program source code into machine code, period. That job is the responsibility of another piece of software, known as the interpreter or compiler, a machine code program which effectively tells the computer how to perform the translation from source code to machine code. The computer cannot do this job by itself as computers only understand machine code and nothing else.

An interpreter simply converts each statement of source code into the equivalent machine code and executes it, one statement at a time. This is extremely slow because subroutines that are called many times must be translated each time they are called, for instance. Thus the source code must always be executed within the interpreter software.

A compiler, on the other hand, converts the entire source program into object code which can then be linked to produce the required machine code. Once linked, the machine code will execute without any further interpretation, and is therefore known as a standalone executable.

Can an extern function be defined in a C header file?

Declared is the right word. (Don't define functions in headers, unless you really know what you are doing.)

Assigning a value to a variable in a declaration statement is called?

Answer is; initialization

*** Edit***

Initialization is correct.

Page 59

Programming Logic and Design by Tony Gladdis

Write a C program To check whether given number is a prime number or not?

The brute force way would be to iterate through all the integers smaller than the sought number and check the number is divisible by each of them. However this algorithm is extremely inefficient, but improving upon the simple idea, we can come up with an algorithm:

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

/*

*

*/

int main(int argc, char** argv) {

int checked = 72; //put your number that you want to check

int temp = 2; //the temporary variable to check against

char isPrime = 1; //intially assume it is prime

if (checked != 1 checked != 2) {

while (temp <= sqrt((double) checked)) { //only have to check up to the square root of checked

if (checked % temp 0) {

temp += 1; //only have to check odd numbers } else {

temp += 2; } } }

if (isPrime) {

printf("Checked is prime!\n"); } else {

printf("Checked is not prime!\n"); }

return (EXIT_SUCCESS);

}

or a better edited version here: http://img689.imageshack.us/img689/8164/primecodec.png

Is it necessary to initialize the const variable in c?

A constant variable cannot have its value changed at program run time.

IF we r terminated at the middle of the program execution in UNIX what will happen to the program it will continue running or terminate or the op will be send to your mail?

It depends on whether the program responds to a hangup signal or not. If you start the program with a 'nohup' command then it will continue to execute.

What is meant by counting and indexing in assembly language programming?

The Counter Register (RCX and all smaller variants) are used to count loops with a known value, such as counting from 1 to 100. The indexing registers, such as RSI, are used with data manipulation commands, such as reading and writing hardware ports, moving data from one location to another, etc. The term indexing is the same as in other languages, where an index is an offset into an array.

Turbo C example of program that implements Stack?

/*Linked List Implementation of STACK*/

/*Checking of parenthesis in expressions*/

#include<conio.h>

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

#define M 100

typedef struct node *nd;

struct node

{

char p;

nd next;

}NODE;

void getExpression(char expr[]);

void checkParenthesis(char expr[],int *);

void dispResult(int);

nd top,bottom;

int main(void)

{

char expr[M];

int r;

getExpression(expr);

checkParenthesis(expr,&r);

dispResult(r);

return 0;

}

void getExpression(char expr[])

{

clrscr();

printf("Input an expression: ");

gets(expr);

}

void checkParenthesis(char expr[],int *r)

{

int f=0,l,i;

char e;

nd tp,t;

top = NULL;

bottom = NULL;

l = strlen(expr);

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

{

e=expr[i];

if(e == '(')

{

tp = malloc(sizeof(NODE));

tp->p=e;

if((top==NULL) && (bottom==NULL))

{

tp->next = NULL;

top = tp;

bottom = tp;

}

else

{

tp->next=top;

top=tp;

tp=NULL;

}

}

else if(e==')')

{

if(top==bottom)

{

if(top==NULL)

{

f=1;

break;

}

else

{

top=NULL;

bottom=NULL;

}}

else

{

t=top;

top=top->next;

t->next=NULL;

}

}

}/*end of for loop*/

if(top != NULL)

f=1;

*r=f;

}/*end of function checkParenthesis*/

void dispResult(int r)

{

clrscr();

if(r==0)

printf("The expression has a balance parentheses.");

else if(r>0)

printf("Unbalanced parentheses.");

getch();

}

/*

if(top==bottom)

{

top=NULL;

bottom=NULL;

}

else

{

if((top==NULL)&&(bottom==NULL))

{

f=1;

break;

}

else

{

t =top;

top = top->next;

t->next = NULL;

}

}

}

*/

/*eahjie*/

How to you convert asp to mp3?

simply all you need to do is rename the file , like for example if the file name is ( loveme.asp) rename it to ( loveme.mp3) and that is all you need to do to change the formate.

thank you

What are the two common problems with pointers?

Memory leakage, problems with tracking and managing.

Can an float value be assigned to int variable?

Yes, an integer can be assigned as a float value.
But it get stored as a float value, that is an implicit type conversion occurs during compilation.Smaller data types are convertible to larger data types.

eg:

float b=12;// an integer constant is assigned to a float variable
printf("%f",b);// when printing b it will print as 12.000000