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

What converts and executes one statement at a time in computers?

There are number of compilers that are used . A compiler that executes and translates on statement at time is called interpreter. An interpreter is a compiler that executes one line at a time and if an error occurs it need to be corrected at the same point of time else the further execution will stop.

Why can you not declare void variables in c?

All names must be declared in C so that the compiler knows what each name represents even if the definition of that name has not yet been compiled. Without a declaration, the compiler cannot know what operations are permitted upon the name and therefore cannot notify the programmer of syntax errors.

What is the size of void data type?

Data-type void has some special features:

- it doesn't have values

- it doesn't have size

- you cannot declare variables with it

- void *pointers cannot be dereferenced

How a program in c that will add 2 numbers without using any plus operator?

int main()

{

int a=10,b=20;

while(a--)

b++;

printf("%d",b);

}

or: a -= -b;

How do you use fseek function in c?

Answer

First a few points.

I do not know if you intended it but you are asking this of a C++ expert not a C expert. I mention this as fseek forms part of the standard C library file operations. Of course the C++ standard library inherits these functions, but they are not directly compatible with C++ IOStreams. You therefore have to have opened the file using the C fopen function, and close it using the C fclose function.

Next, you have to be careful when using fseek with text files. Things like end of line character sequences and the size of characters used can make a difference to the position values you need to pass to fseek via its offset parameter. The fseek function positions to the requested byte position within the referenced file, it knows and cares nothing about characters or their encoding making up the data of the file.

You also have all that silliness to do with character 26 (ctrl-Z) being interpreted as end of file in text mode - a Microsoft hangover from the days of MS-DOS. Then there is the effect caused by skipping over the byte order mark (if there is one), which as far as I know has to do with text files of characters in various Unicode encodings (so hopefully can be ignored in simple cases). See http://unicode.org/unicode/faq/utf_bom.html#BOM for more information on byte order marks.

You ask about positioning to the letter positions. Not all characters are letters and not all characters are printable. As I said fseek knows and cares nothing about the data or meaning of the values in a file and therefore cannot tell a letter from any other character type.

So assuming you meant characters when you mention letters in your question and assuming characters are all the same size and are byte sized then to position to the 45th character when starting with the file pointer positioned at the 20th character you can do the following:

status = fseek( file, 44L, SEEK_SET );

The fseek call shown above assumes file is a FILE * pointing to a valid open FILE structure. 44L specifies the position as a long integer constant, SEEK_SET is a value indicating that 44L is used to specify the position counting from the beginning of the file. As the beginning of the file is at position 0 and not position 1 we have to subtract 1 from the byte number we want if we count the first character as character 1.

The status variable is an int and is used to hold the returned value which is 0 on success and some non-zero value if fseek failed. If fseek fails you should check errno for more details or call a function such as perror as in the MSDN example, which converts the errno value to a string, prefixes the passed text and displays it on stderr (as associated with std::cerr in C++).

Alternatively you could specify the position to move to relative to the current position which would be the value given by the difference between the new position from the current position, thus 45-20 = 25:

status = fseek( file, 25L, SEEK_CUR );

Here the way the position value is interpreted is specified as SEEK_CUR, meaning to count from the current file position. This assumes of course that the file pointer position is in fact at position 19 (i.e. the 20th byte counting from 0) to start with. If it were at (say) position 112 then it would end up at position 137.

The reverse would be either:

status = fseek( file, 19L, SEEK_SET );

That is move to position 20 as counted from 0, the beginning of the file.

Or:

status = fseek( file, -25L, SEEK_CUR );

Which means move to the current position less 25, which assuming the file pointer is positioned at position 44 (i.e. byte 45 counted from 0) to start with would position it to position (44-25) = 19 (i.e. byte 20 counted from 0).

If you look carefully at the signature for fseek then you would notice that the offset parameter is specified as a long value - that is it is a signed value and so can be negative.

I should note that we could also position relative to the end of the file by specifying SEEK_END as the third parameter value. However this would mean we would need to know how long the file was in bytes so we can calculate the distance from the end of the file to the positions we require and so seems to be more effort than it is worth in this case.

Hope this helps. If you require further information then please ask another question.

Write a program to find a square of first ten integers?

#include<iostream.h>

#include<conio.h>

void main()

{

for(int i=1;i<=10;i++)

{

cout<<i*i;

}

getch();

}

How do you pass an array as a parameter?

Answer
Unfortunately your question is to broad. All progamming languages vary in the way things are done. I will just give a general way of doing it.
You have to pass the multidimensional array into the function by including it with calling the function. On the receiving end you have to declare another multidimensional array so the information can be passed into it. Depending on the language, you may not be passing in a multidimensional array, instead that array may be stored in an object which you can pass instead.
Hope this helps some.



-Ashat-
in C, when passing two dimensional arrays the compiler needs to know the width so it can calculate memory offsets.

passing a 2d array of width 4:

void
Func(type array[][4]);

What is the difference between cc plus plus and java?

C is a procedure oriented language ,Where C++ & java are object oriented language.
But java is platform independent.
So generally C is called POP.
C++ is called OOP.
But java is OOP , which is platform independent.
If java does not support primitive data type then it is called as pure object oriented language.

What do you call the process of subdividing a problem into smaller sub problems?

what do we call the process of subdividing a problem into smaller sub-program.c programing

What is the difference between strcpy and strncpy?

strcpy - copy a string to a location YOU created (you create the location, make sure that the source string will have enough room there and afterwards use strcpy to copy)

strdup - copy a string to a location that will be created by the function. The function will allocate space, make sure that your string will fit there and copy the string. Will return a pointer to the created area.

To solve sin series in c language?

# include <conio.h>

# include <stdio.h>

unsigned int factorial(int);

void main()

{

unsigned int f;

int a,i,g=0,c=1,j=-1;

clrscr();

scanf("%d",&a);

printf("sine series up to %d terms",a);

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

{

f=factorial(c);

j=j*(-1);

printf(" [(%d(x^%d))/(%d)] ",j,g,f);

if(i!=a)

printf("+");

c=c+2;

g=g+2;

}

getch();

}

unsigned int factorial(int x)

{

int fact=1,i;

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

fact=fact*i;

return fact;

}

How do you write algorithm of Program in C to print hello 10 times?

#include<stdio.h>

int main()

{

int i;

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

{

printf("Hello Sok Sabay\n");

}

}

How many copies of the Common Language Runtime CLR can be executing on a machine?

As many as required by the programs that require a specific version, up the maximum of 4 different version. DotNet v1.0 programs require CLR v1.0. DotNet v1.1 requires CLR v1.1. DotNet 2.0, 3.0 and 3.5 require CLR v2.0 and DotNet v4.0 and 4.5 require CLR v4.0.

How do you subtraction two numbers using bitwise operator?

#include<stdio.h>

#include<conio.h>

void main()

{

int x,y;

clrscr();

printf("\n enter the elements\n");

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

printf("\n before swaping x=%d,y=%d",x,y);

x=x^y;

y=y^x;

x=x^y;

printf("\n after swaping x=%d y=%d",x,y);

getch();

}

How do you save a C program?

One does not normally save programs. Programs are usually binary files containing a list of executable instructions and internal data. The C++ programs are a suite of executables that allow the creation and management of source code files to create new executables. We do not need to save these programs -- they were stored on disk when the suite was first installed.

What are the advantages and disadvantages of a compiler?

The advantages are that the compiler can see each translation unit as a whole and can therefore optimise the resultant machine code accordingly. For instance, trivial functions that are accessed often, such as array suffix operators, can benefit from inline expansion, thus eliminating the need for an otherwise costly function call.

Also, constant expressions can be evaluated at compile time using compile-time evaluation. For instance, consider the following code:

constexpr int fac (constexpr num) {

return num==1?1:fac (num-1);

}

void f() {

int x {fac (7)};

// ...

}

A good compiler will replace the recursive function call fac(7) with the constant value 5040.

In addition, compilers (along with the corresponding linker) help eliminate many common errors such as static type errors, syntax errors and linkage errors. They can also test programmer's assumptions through static assertions. The more errors detected and eliminated at compile time, the fewer errors there will be at runtime, which will primarily consist of logic errors.

The disadvantage of compilers is that compilation can take a long time, particularly with large projects. Each time the program is modified, it must be recompiled. compilation times can be reduced by precompiling headers that are not expected to change very often, creating intermediate files that are much faster to compile. There is also no need to recompile translation units that are unaffected by changes in code, most of which only occur due to changes with a common header. Nevertheless, a non-trivial application can still take several minutes to produce a working executable and the more time spent compiling the less time you can spend debugging the runtime logic.

Interpreted languages are executed in real-time without the need for compilation. However, execution times are very much slower due to the need to constantly translate high-level source code into low-level machine code.

There are, however, languages that are both compiled and interpreted. Java is a typical example. The source code is first compiled to an intermediate code known as Java byte code which can then be interpreted by the Java virtual machine to produce the machine code. Unlike traditional compilers which produce native machine code that only runs one the architecture it was intended for, Java byte code is completely portable and can be executed upon any machine with a suitable Java virtual machine implementation, which is pretty much everything these days. However, interpreted languages (including Java) are not suitable for low-level programming, they are only suitable for applications programming. Compiled languages such as C and C++ are suitable for all types of programming, hence they are termed general purpose languages.

What is the advantage of doubly linked list over Doubly linked list?

A doubly linked list can be traversed in both directions (forward and backward). A singly linked list can only be traversed in one direction.

A node on a doubly linked list may be deleted with little trouble, since we have pointers to the previous and next nodes. A node on a singly linked list cannot be removed unless we have the pointer to its predecessor. On the flip side however, a doubly linked list needs more operations while inserting or deleting and it needs more space (to store the extra pointer).

What is the difference between stack and array?

Briefly, there are two main differences between an array and a stack. Firstly, an array can be multi-dimensional, while a stack is strictly one-dimensional. Secondly, an array allows direct access to any of its elements, whereas with a stack, only the 'top' element is directly accessible; to access other elements of a stack, you must go through them in order, until you get to the one you want. I hope this answered your question.

OK?

What are disadvantages of a linked list over an array?

A linked list is better bcoz:

1. A linked list can be grown to any size whereas a statically allocated array is of a fixed size and hence can cause problems if you try to insert beyond that.

2. Deletion of elements is a problem in arrays. You either have to move all the elements following the deleted element forward which is a waste of time or you have to place a sentinel indicating that the element in that position is deleted which causes a waste of space.

On the flip side, arrays are easier to handle because their memory allocation is done once and for all(atleast till you need more space and have to reallocate) and because there is no hassle with pointers.

How is a multi-dimensional array defined in terms of a pointer?

Yes. More specifically, they can be used to represent a dynamic multi-dimensional array.

As most people know, for a one-dimensional dynamic array, you simply need a pointer to the first element in the array, where each element contains an object of the same type as the pointer. The pointer can be passed around functions just as if it were a static array, the only difference being the requirement to pass the upper bound of the array as well as the array itself.

For a two-dimensional array, you need a pointer-to-pointer which points to the first element of a one-dimensional pointer array, where each pointer in that array points to a one-dimensional array of objects. The pointer-to-pointer must be the same type as the pointers and the objects.

For a three-dimensional array you need a pointer-to-pointer-to-pointer. And so on. Each additional dimension simply adds a new level of indirection, and a new level of one-dimensional pointer arrays.

Of course multi-dimensional arrays are only useful if every dimension is fully utilised and doesn't require too much in the way of resizing. If that is not the case, then you may get more efficient memory consumption from a vector of vectors (of vectors), which allows dynamic resizing at every level without having to copy existing elements. The downside is you lose the random access provided by the array.

What is the c program to find the octal equivalent of an integer?

void Decimal_to_Octal()
{
int n,r[10],i;
cout<<"Enter a number to find it's octal equivalent";
cin>>n;
cout<<"The octal equivalent of "<for(i=0;n!=0;i++)
{
r[i]=n%8;
n=n/8;
}
i--;
for(;i>=0;i--)
cout<count<}

Value of jc higgens model 50 30-6?

I have a JC Higgins model 60 in pristine condition, and it it worth, supposedly, around $150. But, it is a GREAT gun, and to me, worth a whole lot more. It was the first gas-operated semi-auto shotgun on the market, and kicks a lot less than a newer gas-operated Remington semi-auto than I've got. I'll never part with it. Al In good to excellent con . 125 to 200 dollars these guns came out in 1956 and when they first were introduced they were one of the most advanced semi autos out there they are still nice guns and have some value