What is an array and what does index mean in an array in c?
An array is an aggregate of elements, where memory is allocated to accommodate a given number of elements of a given type. The name of the array serves as a reference to the first element of the array. Unlike ordinary (non-array) variables, all the other elements of an array have no name; they are anonymous. However, all elements of an array have identity (they have an address) so if we know the address of an element within an array we can easily refer to it by that address.
Given that each element is of the same type and therefore the same size (in bytes), we can easily calculate the address of each element offset from the start of the array. That is, the nth element of an array A of type T will be found at address A + sizeof(T) * (n-1). Although we are free to use "pointer arithmetic" like this to calculate the individual addresses of each element, C provides us with a much more convenient notation called the array suffix operator.
The array suffix operator applies to pointer variables only. Fortunately, all arrays implicitly convert to a pointer at the slightest provocation so we don't have to do anything special to use them. The operator is denoted using square brackets [] such that for an array A we can refer to its nth element as A[n-1]. Given that A is of type T, the compiler has enough information to generate the required pointer arithmetic for us: A + sizeof(T) * (n-1).
Note that array indices are in the range 0 to n-1 for an array of n elements. Attempting to access elements outwith this range has undefined behaviour, so it is important that we take steps to ensure all indices are kept within the bounds of the array. For fixed-length arrays, we can simply use a constant to store the array length, but for variable-length arrays we must keep track of the length using a variable. To range-check a given index against a given length, n, the index must be in the closed range [0:n-1]. However, array index ranges are often denoted using half-closed notation, [0:n), which essentially means 0 <= index < n.
the decryprtion code function is
void decrypt_mono(char word[],char cypher[])
How do you write a c program to find prime numbers between 1 to 10000 using functions?
You need two utility functions. The first determines if a given number is prime or not. The second finds the next prime after a given number.
The following function can be used to determine if a given integer is prime:
bool is_prime (const unsigned num) {
if (num<2) return false;
if (0==(num%2)) return num==2;
unsigned max_factor = (unsigned) sqrt ((double) num) + 1;
unsigned factor;
for (factor=3; factor<max_factor; ++factor)
if (0==(num%factor)) return false;
return true;
}
The following function can be used to determine the next prime after the given integer:
unsigned next_prime (unsigned num) {
while (!is_prime (++num));
return num;
}
Now you can print a series of primes using the following:
int main (void) {
unsigned num=1;
while (num<10000) {
num = next_prime (num);
printf ("%d is prime\n", num);
}
return 0;
}
In C: nothing
in TurboC: datafiles, necessary to graphics modes
What is a Flow chart for finding factorial of a given number using recursion function?
no answer....pls post
How can you increase the precision of the double in c?
no you cannot increase the precision of double itself in C
Give examples for pointers within pointers?
If you mean pointers referring pointers then here you are:
int main (int argc, char **argv)
{
printf ("argv (pointer) is %p\n", argv);
printf ("*argv (pointer) is %p "%s"\n", *argv, *argv);
printf ("**argv (char) is %c\n", **argv);
return 0;
}
// create an BufferedReader from the standard input stream
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String currentLine = "";
int total = 0;
// read integers
System.out.print("Input an integer: ");
while (!(currentLine = in.readLine()).equals("")) {
int input = 0;
try {
input = Integer.valueOf(currentLine);
total += input;
} catch (final NumberFormatException ex) {
System.out.println("That was not an integer.");
}
System.out.print("Input an integer: ");
}
How do you reverse a string with array and function?
<?php
$str = "1234567";
$strArr = str_split($str); //split up $str by 1 character
$strlen = strlen($str) - 1; //get length of $str - 1 since the $strArr starts at 0
for($i=$strlen;$i>=0;$i--)
{
echo $strArr[$i];
}
?>
What is exception handling in object oriented languages?
Exception is a event which can interrupt a normal flow of your program. In other way, exception is a abnormal condition which can occur during the execution of a program. Yes , we can handle exceptions through try, catch, finally, throw and throws.
Are structures and pointers related in c plus plus?
Not really, but you can have:
- a pointer pointing to a structure (FILE * is an example)
- a pointer pointing to a structure-member (eg: struct tm tm; int *ip= &tm.tm_year)
- a structure-member that is a pointer (any type)
Example:
typedef struct TreeNode {
struct TreeNode *left, *right;
int data;
} TreeNode;
TreeNode *root = (TreeNode *)calloc (sizeof (TreeNode), 1);
How do you swap two variables using third variable in flow chart?
To swap two variables using a third variable in a flowchart, start with the initial values of the two variables, say A and B. Use a third variable, C, to temporarily hold the value of A (C = A). Next, assign the value of B to A (A = B), and finally, assign the value of C back to B (B = C). This sequence effectively swaps the values of A and B.
What is near far and huge pointers How many bytes are occupied by them?
Near, far, and huge pointers are different types of pointers used to reconcile the different addressing models of the Intel 8086/8088 class processors, running in a 16-bit operating system such as Windows 3.x, as well as any of the newer incarnations running in real mode or virtual 8086 mode.
A near pointer can address something within one 64Kb memory segment, containing only an offset, and it takes two bytes. The segment is implied by context, and is usually the data segment, selected for the addressing model.
A far pointer can address anything in the 1Mb memory1, containing both a segment and an offset, and it takes four bytes.
A huge pointer is a normalised far pointer, which means its offset part is always between 00H and 0FH.
In 32-bit mode a pointer can address anything in 4Gb memory, containing a flat 32-bit offset, and it takes four bytes. (In this mode segments have no significance.) It only works, however, when there is support for it, such as the WIN32 extension of Windows 3.x.
---------------------------------------------------------------------------------------
1In the 80286 or higher, running in protected mode, in OS/2, the segment portion of the pointer is actually a descriptor selector, so 1Mb addressibility depends on the operating system environment.
far huge near pointer is an oxymoron. far points to memory outside of the normal address space. near points to memory within the normal address space, is the default, and usually is not needed. I've never seen huge before. What is the target architecture?
Near, far, and huge pointers are a construct (usually) in the Win16 environment running on an 8086/8088 or later in real mode, such as Visual C/C++ 1.52. In this environment, near pointers are 16 bits, and far and huge pointers are 32 bits.
Add to the front is constant time O(1). Adding to the end is linear time O(n). If the list maintains a pointer to the last node (as well as the first node), insertions can be done at either end in constant time.
How do you write triagraph series code in c?
You don't. Trigraph sequences are outdated by thirty years.
What shoul you do when there is a leakage of space in terms of array?
If you have a memory leak, you should find it and fix it. It is a bug. It does not matter if it is an array or not. It is still a bug, and it needs to be fixed.
Write a program that takes a binary file as input and finds error check using different mechanism?
networking
Write c program that converts Full name into initial?
main()
{
char firstname[10], middlename[10],lastname[20];
clrscr();
printf("\nEnter First Name :");
scanf("%s", firstname);
printf("\nEnter Middle Name :");
scanf("%s", middlename);
printf("\nEnter Last Name :");
scanf("%s", lastname);
printf("\n%c. %c. %s",firstname[0],middlename[0],lastname);
getch();
}
I did it just for sake of time pass.............
Program to find sum of n numbers using recursion function?
int sum(n)
{
if (n==0)
return 0;
else
return n+sum(n-1);
}
int n;
float sum;
typedef struct _node { float value; struct node *next;} node;
struct node *head;
struct node *ptr;
build_list(&head);
for (n=0, sum=0., ptr=head; ptr!=null; sum+=ptr->value, ptr=ptr->next, n++);
if (n>0) printf("n: %d mean: %f\n", n, sum/n); else printf("no elements\n");
What are preprocessor directives or statements?
For example:
define a symbol
undefine a symbol
include another file
conditionally exclude/include parts
etc
As the name suggests, a preprocessor directive modifies the source code before the compiler sees it. This way the developer can keep the logic at a high level while the compiler does all of the work. As an example:
# define N 5
if (TestingValue == N)
is cleaner code and easier to change should the value for N change. It leads to better modular code for code maintainers.