Should I learn C or C plus plus first if I want to learn C?
Very! C++ isn't the best language out there, it certainly has its issues, but it's very powerful. It's also fairly low-level, as far as modern languages are concerned. Python has all the power with few of the costs. If you already know how to program, you should be able to pick it up in less than two hours. Most the concepts you learned in C++ (inheritance, polymorphism, etc) still apply, too. Python has the advantage of plenty of super easy-to-use libraries for many thing (such as downloading a web page). It can't hurt to try, so give Python a spin and see if it benefits you.
see related link below
In C:
#include <stdio.h>
int
main(void) {
int i, sum=0;
for (i=10; i<=40; i+=2) {
sum += i;
}
printf("%d\n", sum);
return 0;
}
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("Enter a Character");
scanf("%c",&ch);
if(ch>=65 && ch<=90)
ch=ch+32;
printf("Upper Case =%c",ch);
getch();
}
What is the difference between interpreter and parser and compiler?
in my personal point of view i would say a parser is more like "one-directional" "automatic" vs. an interpreter, the interpreter has more "intelligence"
How you describe operations of stack ADT using c template functions?
No, because C does not support the concept of template functions. Template functions only exist in C++, never in C.
Infix Expression :
Any expression in the standard form like "2*3-4/5" is an Infix(Inorder) expression.
Postfix Expression :
The Postfix(Postorder) form of the above expression is "23*45/-".
Infix to Postfix Conversion :
In normal algebra we use the infix notation like a+b*c. The corresponding postfix notation is abc*+. The algorithm for the conversion is as follows :
Example :
Let us see how the above algorithm will be imlemented using an example.
Infix String : a+b*c-d
Initially the Stack is empty and our Postfix string has no characters. Now, the first character scanned is 'a'. 'a' is added to the Postfix string. The next character scanned is '+'. It being an operator, it is pushed to the stack.
Stack
Postfix String
Next character scanned is 'b' which will be placed in the Postfix string. Next character is '*' which is an operator. Now, the top element of the stack is '+' which has lower precedence than '*', so '*' will be pushed to the stack.
Stack
Postfix String
The next character is 'c' which is placed in the Postfix string. Next character scanned is '-'. The topmost character in the stack is '*' which has a higher precedence than '-'. Thus '*' will be popped out from the stack and added to the Postfix string. Even now the stack is not empty. Now the topmost element of the stack is '+' which has equal priority to '-'. So pop the '+' from the stack and add it to the Postfix string. The '-' will be pushed to the stack.
Stack
Postfix String
Next character is 'd' which is added to Postfix string. Now all characters have been scanned so we must pop the remaining elements from the stack and add it to the Postfix string. At this stage we have only a '-' in the stack. It is popped out and added to the Postfix string. So, after all characters are scanned, this is how the stack and Postfix string will be :
Stack
Postfix String
End result :
What variable scope is preferable?
Shorter lifespan, the better (preferable): local.
In some languages, local means within a {-} or begin-end pair, not necessarily a method/function. For example:
void MyDummyOperation() {
int i;
// 10+ lines of codes before the first time of using i
}
void LocalDemo() {
if (1==2) { int i = 0; ....}
}
Notice the local variable int i is declared at the true-branch of the if-statement (although the condition will not be evaluated to true) in LocalDemo() method. That variable cannot be seen outside of that scope, while the one in MyDummyOperation() has a life span of the entire function.
Write an assembly language program for arranging nos in the ascending order?
title ascending order using bubble sort
.model small
.stack 64
.data
a db 34h,78h,56h,47h
si_ze dw $-a ;si_ze=no of elements
.code
bubsort:
mov ax,@data
mov ds,ax
mov bx,si_ze
dec bx ;bx=no of passes needed to complete sorting(n-1)
outlup:
mov cx,bx ;cx=no of comparisions to be performed in a pass
mov si,0
inlup:
mov al,a[si]
inc si
cmp al,a[si]
jb go_on
xchg al,a[si]
mov a[si-1],al
go_on:
loop inlup ;dec cx,until cx=0
dec bx
jnz outlup
int 3 ;breakpoint interrupt
align 16
end bubsort
What is the height of a complete binary tree of height h have?
Minimum is h nodes
(Maximum is 2h+1 - 1 nodes, if tree consisting of only one node is considered to have height of 0. if you consider a tree with one node to be a height of one, then the minimum nodes is (2^(h-1)) 1 nodes.
Minimum number of nodes in a binary tree of height is 2h+1.
For example, if the height of the binary tree is 3, minimum number of nodes is
2*3+1=7.
Well What makes it move?? FART XD Sux ma Furoqin Shoroqin Shiaot.
What is external variable in c language?
The "extern" declaration in C is to indicate the existence of, and the type of, a global variable or function. A global variable, or a global function, is one that is available to all C modules (a single C module is typically a single .c file). An extern is something that is defined externally to the current module. In many cases, you can leave off the extern qualifier and not notice any difference because the linker can collapse multiple definitions to one. But the intent is then unclear in the code, and the code is error prone in case of typos. It is much clearer to define the global in one place, and then declare extern references to it in all the other places. When refering to globals provided by a library, especially a shared library, this is even more important in order to ensure you are talking about the correct, common instance of the variable. Declaring a variable as extern will result in your program not reserving any memory for the variable in the scope that it was declared. For instance (as example) if a program's source code declared the variable var as a global volatile int in foo.c, to properly use it in bar.c you would declare it as extern volatile int var. It is also not uncommon to find function prototypes declared as extern.
A good C manual will certainly answer this more completely.
What is bottom up approach in C programming?
Top down and bottom up programming are two approaches or methodologies employed for designing structured programs in C.
TOP DOWN APPROACH
In a top down approach a program(structured) is designed by using the top down methodology as follows..
First the overall structure of the program is designed and it is defined and then it is followed by the designing of individual functions..
BOTTOM DOWN APPROACH
The bottom down approach is just the opposite of the top down approach..
ie, the program is designed by first designing the individual functions followed designing of overall program structure
How exactly does a computer understand machine language?
You must learn it. You can search for keyword : Assembly.
1. An array cuts down on the number of variables that need to be declared.
For example, if you wanted to store the numbers 1 to 10 without using an array you would literally have to declare ten separate variables.
Dim int1 as Integer = 1
Dim int2 as Integer = 2
Dim int3 as Integer = 3
Dim int4 as Integer = 4
Dim int5 as Integer = 5
Dim int6 as Integer = 6
Dim int7 as Integer = 7
Dim int8 as Integer = 8
Dim int9 as Integer = 9
Dim int10 as Integer = 10
Which is monstrously difficult to read and use further along in your code. A better way of doing it would be to use one variable; an integer array.
Dim intArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Using this example you use the same variable throughout your code and access different parts of it as follows;
Dim intArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Dim intTemp as Integer
MsgBox(intArray(0))
MsgBox(intArray(4))
This example displays two textboxes which will display the number 1 and 5 to the user (Note that array starts at zero)
2. An array can be used in itterative procedures such as a For... Next loop.
For example if we use the previous example of an integer array containing numbers 1 through 10, and with this array we want to display every number to the user.
Without an array this is an almighty block of code with a minimum of 20 lines, 10 declaring each variable and 10 outputting it to the user. With an array this can be reduced to four lines.
Dim intArray() As Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
For i = 0 to intArray.Length
MsgBox(intArray(i))
Next
The importance of this is that in our example we only have ten numbers stored, in the real world you could have hundreds. Declaring hundreds of variables and messing around with them will take up memory, obfuscate the code immensely and make it virtually unchangeable.
With the above example that array could be any length and contain a thousand variables and still function the same.
3. An array can be declared as a variable length.
Whilst it's all well good saying we have an example array containing numbers 1 through 10, it is unlikely to ever be that simple; we will always want to store an unknown amount of data at runtime.
Just declaring variables in the code wouldn't work for this because they would need to be hardcoded.
In this example we will pretend a form has been made with a listview containing a hundred items, when a user clicks a button we want to store everything they selected in the listview. (If you don't know what a listview is I would ask that question as well)
Dim intVarArray(ListView1.SelectedItems.Count - 1) as Integer
For i = 0 to ListView1.SelectedItems.Count - 1
intVarArray(i) = ListView1.SelectedItems(i).ToStringNext
To do this using nothing but variables would be near impossible as you wouldn't know how many items the user would select, as such you would have to declare a hundred variables and write hundreds of lines of code to do something that can be covered in four lines.
4. An array can be resized on the fly, either destroying or preserving existing data.
In the above example we created an array of variable length and then stored some data from a made up listview control, but it's possible when working in the real world we may need to add things to that variable.
We can Redim an array to change its length.
Dim intArray(9) as Integer
Redim intArray(14)
This declares a variable of an array of integers, sets the length to 10 and then redefines that array as an array of length 15. This will completely remake the variable destroying any data held within it.
Dim intArray(9) as Integer = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Redim Preserve intArray(14)
intArray(10) = 11
intArray(11) = 12
intArray(12) = 13
intArray(13) = 14
intArray(14) = 15
This declares a variable of length 10 and stores the number 1 to 10 inside it, it then redefines the variable as length 15 but preserves the data within it (It then adds the number 11 to 15 to that variable).
5. An array can have multiple dimensions.
Dim intArray(, ) as String = {{"White", "Rabbit"}, {"Brown", "Bear"}, {"Blue", "Water"}}
This declares something more unique than any other type of single variable, a multidimensional array, and stores some data within it.
--
Ac532 Answer:
Arrays can be disposed by using the .Dispose which means all allocated memory toward using the array will be lost meaning that your program will run faster.
What is the difference between getcher and getch statements in C?
If you are referring to getchar(), it returns a single character as an 'int'.
'scanf' allows the user to input many different types of variables, and converts them accordingly using a format specified by the user.
If you type 'man getchar' and 'man scanf' you will get additional information on how to use them.
How is memory allocated to arrays?
It depends where the array is declared and whether or not it is fixed-length or variable-length. The only thing all arrays have in common is that the memory is allocated contiguously. Fixed length arrays are arrays where the length is known at compile time while variable length arrays have unknown length and are allocated at runtime.
Fixed-length arrays can be allocated statically, on the call stack (local memory) or on the heap (the free store) while variable length arrays must always be allocated on heap. Fixed-length arrays should use a constant variable to refer to the array length consistently while variable-length arrays should use a (mutable) variable. Arrays allocated on the heap must also use a pointer variable to keep track of the start address. The array (or pointer) and its length should always be declared in the same scope. Storing both in a data structure makes it easier to keep track of the array and its length.
Static arrays are always fixed length and are allocated at load-time, before entry to the main function (even if declared in the main function or in another function entirely). The memory remains allocated until the program terminates. If there is insufficient memory available, the program itself will fail to load. It is recommended you use static memory sparingly and avoid the use of globals whenever possible.
Local arrays are also fixed length but are allocated on the call stack at runtime as and when they come into scope. The memory is released automatically when the array falls from scope. The stack is fixed-length and therefore has limited capacity, so local arrays should be used sparingly.
Variable length arrays and fixed-length arrays allocated on the heap are allocated and released manually (programmatically) at runtime. It is the programmer's responsibility to keep track of the array's start address. If there is insufficient memory available, it is the programmer's responsibility to handle the exception.
Examples:
// Fixed-length array at global scope // Note that all globals are implicitly static:
const int a=10;
int A[a]; // static array of 10 integers
// Fixed-length array at file scope
// Note that all file scope variables are explicitly static:
static const int b=20;
static int B[b]; // static array of 20 integers
// Fixed-length arrays at function scope:
void f ()
{
const int size=100;
static int C[size]; // static array of 100 integers (allocated at load-time)
int D[size]; // local array of 100 integers (allocated when f comes into scope)
int* E = malloc (size * sizeof (int)); // heap array of 100 integers
// Note: if E is NULL, the allocation failed!
// ...use arrays...
free (E); // release the allocation before E falls from scope!
E = NULL; // good housekeeping!
}
// D is released here
// C, D and E will fall from scope here, however C is not released
// Variable-length arrays at function scope:
void g (const int n)
{
int* F = malloc (var * sizeof (int)); // heap array of n integers
// ...use array...
free (F);
F = NULL;
}
// F falls from scope here.
How a C program to find LCM using while loop?
Problem Statement for LCM:
Enter Two digits by a user and get its LCM
Answer:
#include
#include
void main()
{
int x,y,i,j;
clrscr();
printf("Enter Two Digits");
scanf("d",&x,&y);
for(i=1;i<=x;i++)
{
for(j=1;j<=y;j++)
{
if(y*i==x*j)
{
printf("LCM is %d\n",y*i);
i=i+x;
}
}
}
getch();
}
OR
there will be another easy way to solve it...
Answer:
#include
#include
void main()
{
int x,y,i,;
clrscr();
printf("Enter Two Digits = ");
scanf("d",&x,&y);
for(i=1;i<=x*y;i++) {
if(i%x==0&&i%y==0)
{
printf(LCM is %d",i);
break;
}
}
getch();
}
The IEE standared 32 bit floating point representation of the binary number 19.5 is?
0 10000011 11100000000000000000000
Define flowchart and draw flowchart for GCD of two numbers?
pictorial representation of a program is called a flowchart
What is balanced binary search tree?
A balanced tree is a tree which is balanced - it has roughly the same height on each of its sub-nodes. A balanced tree will have the lowest possible overall height.
For example, a balanced binary search tree will have equal heights (plus or minus one) on the left and right sub-trees of each node. This ensures that operations on the tree always are guaranteed to have O(lg n) time, rather than the O(n) time that they might have in an unbalanced tree.
Certain tree algorithms are designed for ensuring that the tree stays balanced at all times, while maintaining the O(lg n) time for all operations. Such algorithms, such as red-black trees, AVL trees, and others, are generally used in standard library implementation of binary search trees.
How to write printf statement for read characters into array str until the letter p is encountered?
In pseudo-code:
while ( not(end of string) and letter(string at position X) is not 'P' ){
add(array, newposition) = letter(string at position X);
}
How many dimensions you can declare in array?
It seems that the number of allowed array dimensions is implementation specific and not set by the Java specifications. I'm sure that any Java implementation will allow a reasonable number of dimensions for any project you have.
After a quick test, it seems that Java is not limited by an arbitrary number so much as a practical value. If you add hundreds of array dimensions, Java will allow you to do so as long as you have enough memory allocated for Java. After a bit of copy-pasting the program no longer ran, exiting with a StackOverflowError.
Write a C program to display odd numbers from 1 to n where n is accepted from user?
#include<stdio.h>
main()
{
int i=0,j=0,n;
printf("Enter a number:");
scanf("%d",&n);
printf("The first %d odd numbers are:-\n");
for(i=0;i<=n;i++)
{
if(j%2!=0)
printf("%d\n"j);
j=j+1;
}
}
Dennis Ritchie is the creator of C programming language and, with Ken Thompson, the creator of the Unix operating system. He is also co-author of 'The C Programming Language' (Kernighan & Ritchie), which gave rise to what is now known as K&R C, the original version of C prior to what is now known as Classic C.
What is the use of realloc in c language?
Realloc is a function in C. It is used to change the size of a block of memory by expanding it. There are various ways realloc can change the memory size, depending on if there is enough space in the block of memory.