How do I open a .chm file?in Ubuntu or linux??
sudo apt-get install gnochm
sudo apt-get install kchmviewer
sudo aptitude install chm2pdf
Thursday, August 19, 2010
Tuesday, August 17, 2010
MeeGo Dictionary
Maemo - a software platform developed by Nokia forsmartphones and Internet Tablets. It was initially based on theDebian Linux distribution. One of the predecessors of MeeGo, along with Moblin.
Maemo 5 - the default operating system on the Nokia N900, and current latest stable and independent version of Maemo. Based on the GTK toolkit. Aliases: Fremantle
MeeGo - an open source, Linux project which brings together the Moblin project, headed up by Intel, and Maemo, by Nokia, into a single open source activity. Managed by the Linux Foundation. The important thing to note that you end users will mostly be using an edition of MeeGo, MeeGo itself is not a single product (that’s why "will X run/get MeeGo" is a bad question), just like people are using a Linux distributions, not Linux (as in kernel) alone.
MADDE - Maemo(/MeeGo) Application Development andDebugging Environment,
offers the following features:
MeeGo-Harmattan - the default operating system of the Nokia N9. Successor of Maemo 5, but based of the Qt toolkit. Originally named Maemo 6, but later rebranded as MeeGo-Harmattan (provisional name). It is MeeGo compatible (that is, has a MeeGo API) but is not to be confused with MeeGo 1.0 Handheld (as it is NOT based on MeeGo Core). MeeGo-Harmattan will not be released as a Nokia product for the N900. Aliases: Harmattan, Maemo 6.
QML - a Declarative UI tool, in effect a markup language that defines UI elements and their behavior in a declarative manner, allowing, snappy, whizzy UIs. Present in Qt4.7+
Qt Quick - the Qt User Interface Creation Kit, which consists of QML, a specialized editor in QtCreator and all-around support for the declarative approach. Present in Qt4.7+. Aliases: Qt Declarative, Declarative UI, Bauhaus.
QtMobility - extends Qt with libraries providing additional features for applications targeting mobile platforms. These include the Service Framework and Contact and Bearer Management APIs, Messaging, Sensors, Camera, etc
UI Extensions for Mobile - an extension library for Qt, which contains more than 50 UI elements tailored for mobile user experience. There is a proposal to use Orbit and Qt together withDirect UI as a replacement for the existing S60 'Avkon' set of UI elements in Symbian^4, but has been demonstrated to work on Maemo, too. It was previous known as Orbit before getting renamed to UI Extensions for Mobile (uiemo) and open sourced. Aliases: Uiemo, Orbit
Maemo 5 - the default operating system on the Nokia N900, and current latest stable and independent version of Maemo. Based on the GTK toolkit. Aliases: Fremantle
MeeGo - an open source, Linux project which brings together the Moblin project, headed up by Intel, and Maemo, by Nokia, into a single open source activity. Managed by the Linux Foundation. The important thing to note that you end users will mostly be using an edition of MeeGo, MeeGo itself is not a single product (that’s why "will X run/get MeeGo" is a bad question), just like people are using a Linux distributions, not Linux (as in kernel) alone.
MADDE - Maemo(/MeeGo) Application Development andDebugging Environment,
offers the following features:
- Command-line cross-compiling
- Multi-platform support (Linux (32-bit/64-bit), Windows, Mac OS X)
- Configurable for different targets & toolchains
- Client for the device to simplify the development process
- Will be used as part of future releases of the MeeGo SDK, along with QEMU, to enable cross-OS development.
MeeGo-Harmattan - the default operating system of the Nokia N9. Successor of Maemo 5, but based of the Qt toolkit. Originally named Maemo 6, but later rebranded as MeeGo-Harmattan (provisional name). It is MeeGo compatible (that is, has a MeeGo API) but is not to be confused with MeeGo 1.0 Handheld (as it is NOT based on MeeGo Core). MeeGo-Harmattan will not be released as a Nokia product for the N900. Aliases: Harmattan, Maemo 6.
MeeGo Touch Framework (MTF) - provides the features needed for developers creating applications for touch-enabled devices. Features include standardized window navigation, list and other widget behavior, and common theming for components.
MeeGo Web RunTime - Web Runtime (WRT) allows web developers to use standard web languages — HTML, CSS, and JavaScript — to create applications for mobile devices. WRT exposes the features of the underlying platform so that applications can interact with device data and combine location-based context with web information
Moblin - short for 'mobile Linux', is an open source operating system and application stack for Mobile Internet Devices (MIDs),netbooks, nettops and embedded devices. One of the predecessors of MeeGo, along with Maemo.
QML - a Declarative UI tool, in effect a markup language that defines UI elements and their behavior in a declarative manner, allowing, snappy, whizzy UIs. Present in Qt4.7+
Qt Quick - the Qt User Interface Creation Kit, which consists of QML, a specialized editor in QtCreator and all-around support for the declarative approach. Present in Qt4.7+. Aliases: Qt Declarative, Declarative UI, Bauhaus.
QtMobility - extends Qt with libraries providing additional features for applications targeting mobile platforms. These include the Service Framework and Contact and Bearer Management APIs, Messaging, Sensors, Camera, etc
UI Extensions for Mobile - an extension library for Qt, which contains more than 50 UI elements tailored for mobile user experience. There is a proposal to use Orbit and Qt together withDirect UI as a replacement for the existing S60 'Avkon' set of UI elements in Symbian^4, but has been demonstrated to work on Maemo, too. It was previous known as Orbit before getting renamed to UI Extensions for Mobile (uiemo) and open sourced. Aliases: Uiemo, Orbit
What is MeeGo?
MeeGo
- MeeGo is opensource linux based mobile operating system.
- MeeGo was announced in Febraury2010.
- MeeGo is based on Linux and X11.
- MeeGo is backed up intel and nokia,hosted by non profilt consortium promoting Linux.
- MeeGo is intended to run on devices including handhelds,netbooks,in-car devices,televisions.
- Different userinterfaces tailored to each type of device support for x86 and ARM processors.
- MeeGo is not a product it is a platform for OEM's to build products on.
Why the necessity came for another embedded platform.
- since 2005 nokia has developed the linux based maemo platform for smart phones and tablets.
- since 2007 intel has developed linux based Moblin platform MID's,netbooks,nettops,and embedded devices.
- Both platform are Linux based and aimed at similar markets.
- Here the duplication of effort occurs.
- Even Nokia and Intel wont compete with each other "directly".(phones versus chips)
- It made sense to merge and work together.
Maemo & Moblin the differences
- Processor-Maemo used Atom processors where as Moblin used intel's X86 processers.
- In MeeGo both architectures are supported.
- Packaging-Moblin is based on Fedora core which uses [rpm] package format whereas Maemo is based on Debian which used debian package management system.[apt/deb]
- MeeGo decided to use rpm package format.
Pros and cons of MeeGo
pros
------
- MeeGo is built on two existing and proven platforms.
- Most components are opensource.
- MeeGo has backing of large two companies.
- MeeGo is'nt owned or controlled by any one vendor.
- Core OS developement tools are free.
- Its easier to migrate for Maemo and Moblin developers.
cons
------
- Risks of any new platform
- Not clear which devices will run it.
- MeeGO is not yet directly supported by Nokia Qt SDK.
- only X86 and ARM processors can be used.
- some components are not yet released.
- switch to Qt is new,significant change to GTK + developers.
MeeGo Components
OS Base , Middle-Ware,UX(Experience) Layers
--------------------------------------------------------------
OS Base
---------
Here the Linux kernal and core services are present.
BootLoader,XDriver,Modem Support,Media Codecs.(Hardware adoption sw)
MiddleWare
---------------
Hardware and usage model independent API for native and webbased application.
Qt plays crucial role here.
QtMobility component also exposes some middle level components for mobile devices.
UX (Experience)
-------------------------
- This layer provides different UIs for different devices.all the UI's are based on Qt.
- MeeGO is required for Handheld embedded devices,in-car components,so the UX is easy to design in Qt.
Sunday, August 1, 2010
Qt for mobile developement
Qt is cross platform UI widget toolkit, but also more that that. It is extensive application development framework and suitable also for implementing non-GUI related programs.
Qt supports symbian, maemo, windowsCE mobile platforms.
Qt API is implemented in C++.bindings for other languages like python, java, ruby also exist.
Qt Cross Platform Architecture.

The implementation of qt uses the private implementation programming idiom which separates the interfaces from the platform specific changes. the application just needs to be re-complied for the target platform in the corresponding development environment.
Qt Class Library

Qt object model
Qt expands C++ with Meta Object Model, it adds the following features to c++.
• Hierarchical and query-able object trees.
• Signals and slots mechanism for object communication.
• Events, Event-Filters and Timers.
• String Translation.
• Guarded pointers.
• RTTI[Type Identification and dynamic casting]
• Discoverable object properties.
QObject hierarchy tree
• QObject is the heart of Qt object model and base class of all Qt Objects.
It provides object trees and object ownership with parent-child relationship.
• A parent owns its children, the mechanism provides memory management for object trees, but no garbage collection for other allocations.
• Parent controls the childrens visibility,but a child object can be explicitly hidden.
Object Tree

Here The top most dialog that has a layout set and a push-button that is outside the layout.
within the horizontal layout there is a label,line-edit and a push-button.
Meta –object system
Meta –object system is based on 3 things.
• QObject class
• QObject macro
• Meta object compiler
• The QObject base class has capabilities to support meta object system(connect method that connects a signal to a slot.)
• Q_OBJECT which is declared inside the private section of the class,states that it requires meta object compiler.
• Meta object compiler is executed automatically before the actual compilation,it generates the c++ code which required for the compilation process.
QApplication
QApplication is the one class that handles event loop and the main settings of an application.
No matter howmany widgets may present in an application there must exist one QApplication instance.
The responsibilities of QApplication includes
• Perform event handling.
• Manage application settings like[screen size,font,application stylesheet and many other tasks].
Events in Qt
When something of interest for the application occurs,for example
A key is pressed,
A mouse is moved,
A Network packet has arrived.
Then an event is created. It is represented as an object of the QEvent class. such as QFocusEvent.Information about the event is enclosed with in this event object.
Events are received and handled by event handlers of QObject.The actual event handler depends on the type of event that has occurred. like if the event mouse movement occurs it is handled by
mouseMoveEvent event handler.
Events are mostly created by the underlying window system but they can also be created by the developer too.The application contains an eventloop that manages and sends event to the objects they are meant for.Eventloop is started by calling the QApplication “exec” method after initilisation,in the beginning of every Qt application.typically in the main function.
Generally,no longer interaction can take place before starting this main event loop.
Signals and Slots
signals and slots offer a way to communicate between QObjects.
A Signal can be emitted by a QObject.
A Slot is a member function which can be connected to a particular slot, or can be called in response to a particluar emitted signal call.
Many predefined signals and slots exist.but subclasses can define and add their own ones.
Signature of signal should match the receiving slot.Another common way to implement observer design pattern is to declare an interface class which is then implemented by all observers.
Signals and Slots are easier to use and they dont need to implement an interface.
Signals and Slots offer loose coupling with many to many relationship by nature.it means a class which emits a signal need not know to which slot it is going to connect to.
Signals
A signal is a way to inform a possible observer that something of interest has occurred in side the observer class.
Some example are.
1.A Http request has been sent to a server and asynchronous handling of request has been finished.
QHttp emits a “requestFinished(int id,bool error)”.
2.A value of slider has been changed.
Qslider emits a valueChanged(int value) signal.
3.A Pushbutton has been clicked.
QPushButton emits a clicked(bool checked) signal.
Signals are sent using the keyword “emit”.
Signals are declared by the developer and implemented by the "moc"[meta object compiler.]
1.Signals can never have return type.[void or any return type is not allowed for signals]
2.signals can take any number of arguments.
3.Inorder to connect a signal with a slot the signature of the signal should match with the receiving slot.
And the number of arguments should be equal to the arguments of the slot.
Qt supports symbian, maemo, windowsCE mobile platforms.
Qt API is implemented in C++.bindings for other languages like python, java, ruby also exist.
Qt Cross Platform Architecture.
The implementation of qt uses the private implementation programming idiom which separates the interfaces from the platform specific changes. the application just needs to be re-complied for the target platform in the corresponding development environment.
Qt Class Library
Qt object model
Qt expands C++ with Meta Object Model, it adds the following features to c++.
• Hierarchical and query-able object trees.
• Signals and slots mechanism for object communication.
• Events, Event-Filters and Timers.
• String Translation.
• Guarded pointers.
• RTTI[Type Identification and dynamic casting]
• Discoverable object properties.
QObject hierarchy tree
• QObject is the heart of Qt object model and base class of all Qt Objects.
It provides object trees and object ownership with parent-child relationship.
• A parent owns its children, the mechanism provides memory management for object trees, but no garbage collection for other allocations.
• Parent controls the childrens visibility,but a child object can be explicitly hidden.
Object Tree
Here The top most dialog that has a layout set and a push-button that is outside the layout.
within the horizontal layout there is a label,line-edit and a push-button.
Meta –object system
Meta –object system is based on 3 things.
• QObject class
• QObject macro
• Meta object compiler
• The QObject base class has capabilities to support meta object system(connect method that connects a signal to a slot.)
• Q_OBJECT which is declared inside the private section of the class,states that it requires meta object compiler.
• Meta object compiler is executed automatically before the actual compilation,it generates the c++ code which required for the compilation process.
QApplication
QApplication is the one class that handles event loop and the main settings of an application.
No matter howmany widgets may present in an application there must exist one QApplication instance.
The responsibilities of QApplication includes
• Perform event handling.
• Manage application settings like[screen size,font,application stylesheet and many other tasks].
Events in Qt
When something of interest for the application occurs,for example
A key is pressed,
A mouse is moved,
A Network packet has arrived.
Then an event is created. It is represented as an object of the QEvent class. such as QFocusEvent.Information about the event is enclosed with in this event object.
Events are received and handled by event handlers of QObject.The actual event handler depends on the type of event that has occurred. like if the event mouse movement occurs it is handled by
mouseMoveEvent event handler.
Events are mostly created by the underlying window system but they can also be created by the developer too.The application contains an eventloop that manages and sends event to the objects they are meant for.Eventloop is started by calling the QApplication “exec” method after initilisation,in the beginning of every Qt application.typically in the main function.
Generally,no longer interaction can take place before starting this main event loop.
Signals and Slots
signals and slots offer a way to communicate between QObjects.
A Signal can be emitted by a QObject.
A Slot is a member function which can be connected to a particular slot, or can be called in response to a particluar emitted signal call.
Many predefined signals and slots exist.but subclasses can define and add their own ones.
Signature of signal should match the receiving slot.Another common way to implement observer design pattern is to declare an interface class which is then implemented by all observers.
Signals and Slots are easier to use and they dont need to implement an interface.
Signals and Slots offer loose coupling with many to many relationship by nature.it means a class which emits a signal need not know to which slot it is going to connect to.
Signals
A signal is a way to inform a possible observer that something of interest has occurred in side the observer class.
Some example are.
1.A Http request has been sent to a server and asynchronous handling of request has been finished.
QHttp emits a “requestFinished(int id,bool error)”.
2.A value of slider has been changed.
Qslider emits a valueChanged(int value) signal.
3.A Pushbutton has been clicked.
QPushButton emits a clicked(bool checked) signal.
Signals are sent using the keyword “emit”.
Signals are declared by the developer and implemented by the "moc"[meta object compiler.]
1.Signals can never have return type.[void or any return type is not allowed for signals]
2.signals can take any number of arguments.
3.Inorder to connect a signal with a slot the signature of the signal should match with the receiving slot.
And the number of arguments should be equal to the arguments of the slot.
Tuesday, July 27, 2010
sample cpp questions.
1.Why does main function in C,C++ have parameters? What are they used for?
int main(argc, char* argv[]).
A.argc and argv are the arguments that are passed from the command line when running a program. argc is the number, argv is an array of values.
2. What is the difference between a pointer and a reference?
A.A pointer is a variable that stores the address of another variable. It must be dereferenced before it can access the value held by the other variable. A reference is an alias for another variable. It can be used the same way that the variable can (unless the reference was declared to be const).
3. What is a stream? What kinds of streams are present in standard C++?
A.A stream is an object which you can use for input or output. It accepts other objects via the insertion << or output operators >> .
A stream can be attached to a file.
An input stream can be attached to the keyboard (such as standard input, by default).
An output stream can be attached to the program console (as standard output and standard error are, by default).
A stream can also be attached to a string.
4.What is the need for istrstream,ostrstream in C++?
A. ostrstream directly writes to the strings in memory, without sending to standard output/error.
istrstream directly reads the characters from an array in memory
5. #include
int main() {
QTextStream cout(stdout);
int i = 5;
int j=6;
int* pointer = &i;
int& reference=i;
int& reference_to_pointer=(*pointer);
i = 10;
pointer = &j;
reference_to_pointer = 7;
reference_to_pointer = 8;
cout << "i=" << i << " j=" << j << endl;
}
A. I = 8, j = 6
6.What is ‘Late-Binding’,in which type of functions this occurs?
A.Virtual functions are resolved dynamically depending on the type of object during the runtime .this is called dynamic dispatch or late-binding.which occurs only in virtual functions.
Dynamic_cast operator uses the runtime information about the type of object. this is exclusively used for RunTimeTypeIdentification.
7.What is a smart pointer to the class?
A smart pointer is an object that stores a pointer to object created on heap.
int* iptr = new int;
int* jptr = new int(10);
The standard library has std::auto_ptr as smart pointer
The boost library has s hared_ptr as smart pointer.
It behaves much like an ordinary pointer except that it automatically deletes the heap object at the right time.
int main(argc, char* argv[]).
A.argc and argv are the arguments that are passed from the command line when running a program. argc is the number, argv is an array of values.
2. What is the difference between a pointer and a reference?
A.A pointer is a variable that stores the address of another variable. It must be dereferenced before it can access the value held by the other variable. A reference is an alias for another variable. It can be used the same way that the variable can (unless the reference was declared to be const).
3. What is a stream? What kinds of streams are present in standard C++?
A.A stream is an object which you can use for input or output. It accepts other objects via the insertion << or output operators >> .
A stream can be attached to a file.
An input stream can be attached to the keyboard (such as standard input, by default).
An output stream can be attached to the program console (as standard output and standard error are, by default).
A stream can also be attached to a string.
4.What is the need for istrstream,ostrstream in C++?
A. ostrstream directly writes to the strings in memory, without sending to standard output/error.
istrstream directly reads the characters from an array in memory
5. #include
int main() {
QTextStream cout(stdout);
int i = 5;
int j=6;
int* pointer = &i;
int& reference=i;
int& reference_to_pointer=(*pointer);
i = 10;
pointer = &j;
reference_to_pointer = 7;
reference_to_pointer = 8;
cout << "i=" << i << " j=" << j << endl;
}
A. I = 8, j = 6
6.What is ‘Late-Binding’,in which type of functions this occurs?
A.Virtual functions are resolved dynamically depending on the type of object during the runtime .this is called dynamic dispatch or late-binding.which occurs only in virtual functions.
Dynamic_cast operator uses the runtime information about the type of object. this is exclusively used for RunTimeTypeIdentification.
7.What is a smart pointer to the class?
A smart pointer is an object that stores a pointer to object created on heap.
int* iptr = new int;
int* jptr = new int(10);
The standard library has std::auto_ptr as smart pointer
The boost library has s hared_ptr as smart pointer.
It behaves much like an ordinary pointer except that it automatically deletes the heap object at the right time.
Monday, July 26, 2010
MeeGo Architecture
MeeGo Architecture
MeeGo Software Architecture Overview
The MeeGo platform has been carefully created to provide the components necessary for the best device user experience. As shown in the MeeGo Reference Architecture Overview diagram below, the MeeGo architecture is divided into three layers:
* The MeeGo OS Base layer contains the Linux kernel and core services along with the Hardware Adaptation Software required to adapt MeeGo to support various hardware architectures.
* The MeeGo OS Middleware layer provides a hardware and usage model independent API for building both native applications and web run time applications.
* The MeeGo User Experience layer provides reference user experiences for multiple platform segments; the initial MeeGo release will contain reference user experiences for handhelds and netbooks and additional platform segments will be supported over time.
MeeGo OS Base
Hardware Adaptation Software
There are multiple software components that a hardware vendor must provide for MeeGo to run successfully on their platform architecture, including platform kernel drivers, core architecture additions, kernel configuration, X software additions and configuration, modem support, and hardware specific media components. You can learn more about the hardware enabling process here. These specific software components are called the hardware adaptation software and are detailed below.
Kernel
The kernel is the heart of Linux, and acts as the bridge between applications and the actual data processing done at the hardware level. There are three general categories of additions that MeeGo requires for each supported hardware platform.
* Kernel Drivers: This is the set of software drivers needed to interact with the hardware device. Some examples are drivers for wireless, camera, USB, 3G, Bluetooth, and touchscreen.
* Core Architecture Additions: These are additional packages added to the Kernel to enable certain architecture features. An example would be firmware.
* Kernel Configuration File: This file determines the options needed to get the hardware device working properly. This configuration file is in addition to the general kernel configuration file that is provided within MeeGo, and is specific to the hardware vendor platform. This file details the specific configurations required for the specific device. Examples include device architecture, processor type, device driver configuration options, network support, and kernel debugging options.
X Window System
The X Window System (also known as X11 or simply X) provides the graphical interface and the basic framework for building this interface. There are two general categories of X additions that MeeGo requires for each supported hardware platform.
* Core Architecture Additions: These are additional packages to be added to X to enable certain architecture features. Examples include the graphics controller, display, and acceleration.
* X Configuration file: This file provides configuration and runtime parameters for initializing the X windows system. If there are hardware-specific configuration options required for the X windows system, these details must be added and supplied to the specific hardware platform X configuration file. Examples include the display output and resolution.
Miscellaneous
* Bootloader: The bootloader program's only job is to perform the necessary initializations to prepare the hardware for the operating system, and it contains board- and/or processor-specific code. The bootloader provides the necessary glue between the firmware and the kernel.
* Image Device Format Tool: This provides the details on how to write an image for a specific device. It is a tool used to create a device executable in the appropriate device format.
* Modem Support: telephony framework plug-ins for specific cellular modems
* Hardware-Specific Media Codecs: Codecs that are hardware specific (such as codecs with hardware assist/offload)
MeeGo Kernel
MeeGo uses a Linux kernel from kernel.org, with architecture specific configuration and patches (as needed). Drivers are provided for each supported platform.
Qt
Qt provides application developers with the functionality to build applications with state-of-the-art graphical user interfaces. Qt is fully object-oriented, easily extensible, and allows true component programming.
Component(s): QtGui, QtCore, QtDBus, QtMultimedia, QtNetwork, QtOpenGL, QtScript, QtSql, QtSvg, QtWebKit, QtXml, Qt3Support, QtDeclarative, QtHelp, QtScriptTools, QtTest, QtXmlPattern
Tuesday, November 17, 2009
C Interview Questions
Funny C Questions
Author—Satyendra
1.Write a C program which prints Hello World! without using a semicolon?
a) #include
int main()
{if(printf("HelloWorld")){}
2. Write a small C program to determine whether a machine's type is little-endian or big-endian.?
Big endian order:-Here the “big end” (most significant value in the sequence) is stored first, at the lowest storage address. The most significant byte is stored in the leftmost position
a)#include
int main()
{
unsigned int number = 10;
char *ptr;
ptr = (char *)&number;
if(*ptr)
Printf(“little-endian \n”);
else
Printf(“big-endian \n”);
return 0;
}
3. What is the format specifiers for printf to print double and float values?
a)printf(“%lf , %f”);
%lf - double
%f - float
4. What is the difference between memcpy and memmove?
memcpy memmove
Takes 3 arguments a Void *ptr, const void *cptr , and an int n. Takes 3 arguments a Void *ptr, const void *cptr , and an int.
Copies ‘n’ characters from const void ptr cptr to void ptr ptr and returns void ptr. Copies ‘n’ characters from const void ptr cptr to void ptr ptr and returns void ptr.
Not reliable Reliable when an overlap.like objects cptr and ptr overlap.
4. Write a C program to find the smallest of three integers, without using any of the comparision operators.
a) #include
#include
int main() {
int x = 2;
int y = 1;
int z = 3;
int r;
r = y + ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1)));
r = z + ((r - z) & ((r - z) >> (sizeof(int) * CHAR_BIT - 1)));
printf("%d\n", r);
}
5.What does the format specifier %n of printf function do?
a)Tthe format specifier “ %n” will give the number of characters actually formatted in the printf
function.
Int num = 10;
Char *a= “helloworld”;
Printf(“ %3x,%n ” ,num, &a);
Printf(“%d no of bytes are formatted here into hex”,a);
6. What's the difference between the following two C statements?
const char *p;
char* const p;
a) const char *p; p is a pointer to a constant character;
b) char* const p; p is a constant character pointer;
both are same.
7. How do you print I can print % using the printf function?
a) using %% in the format specifier.
Printf(“%d %% %d” ,a ,b);
Output is a % b;
8. Whats the difference between bitwise and logical operators?
Bitwise Example:
if ((val==1)|(val==2)) printf("%d\n",val);
else printf("False");??
a)bitwise operators are operated on bits. for a bitwise OR operator, both of the left hand side and right hand side values/expressions are evaluated. then the 'evaluated values' are ORed together.
int a = 33, b = 40, c;
c = a | b;
/***********************
33 => 100001 a
40 => 101000 b
------------ OR
41 => 101001 c
***********************/
on the other hand, if expressions are used as the operands of bitwise operator OR:
int val = 2, a;
a = (val == 1) | (val == 2);
printf("%d\n", a);
then the output for the above code is always 1 if val is either 1 or 2, and the output is 0 otherwise. because, in the above case, (val == 1) is evaluated. if this is true, then (val==1) is considered 1, otherwise 0. similarly, (val == 2) is evaluated and is considered 1 or 0 depending if it is true or false. then these two 0 or 1 are ORed together.
logical operators work a little bit different way. say, the code is
(val==1) || (val==2)
the above is a logical expression, whose value is either true or false. to evaluate the above expression, first (val==1) is checked. if this is found true, then the entire expression become true and no further checking is required to check whether (val==2) or not, computer skips checking the right hand side, since they are ORed. if (val==1) is found false, then the value of the expression depends on whether (val==2) is true or false.
similarly, for logical AND operator,
(a==1) && (b==2)
first (a==1) is evaluated. if this is found false, then the entire expression become false and computer skips checking (b==2), since they are ANDed together. if (a==1) is found true, then the checking (b==2) is required to evaluate the whole expression.
so use logical operators when "if this AND that" or "if this OR that" kind of checking is required. go for the bitwise operator when u really need a new bit stream. remember, logical operators skip evaluating in certain conditions where bitwise operators always evaluate both sides.
Author—Satyendra
1.Write a C program which prints Hello World! without using a semicolon?
a) #include
int main()
{if(printf("HelloWorld")){}
2. Write a small C program to determine whether a machine's type is little-endian or big-endian.?
Big endian order:-Here the “big end” (most significant value in the sequence) is stored first, at the lowest storage address. The most significant byte is stored in the leftmost position
a)#include
int main()
{
unsigned int number = 10;
char *ptr;
ptr = (char *)&number;
if(*ptr)
Printf(“little-endian \n”);
else
Printf(“big-endian \n”);
return 0;
}
3. What is the format specifiers for printf to print double and float values?
a)printf(“%lf , %f”);
%lf - double
%f - float
4. What is the difference between memcpy and memmove?
memcpy memmove
Takes 3 arguments a Void *ptr, const void *cptr , and an int n. Takes 3 arguments a Void *ptr, const void *cptr , and an int.
Copies ‘n’ characters from const void ptr cptr to void ptr ptr and returns void ptr. Copies ‘n’ characters from const void ptr cptr to void ptr ptr and returns void ptr.
Not reliable Reliable when an overlap.like objects cptr and ptr overlap.
4. Write a C program to find the smallest of three integers, without using any of the comparision operators.
a) #include
#include
int main() {
int x = 2;
int y = 1;
int z = 3;
int r;
r = y + ((x - y) & ((x - y) >> (sizeof(int) * CHAR_BIT - 1)));
r = z + ((r - z) & ((r - z) >> (sizeof(int) * CHAR_BIT - 1)));
printf("%d\n", r);
}
5.What does the format specifier %n of printf function do?
a)Tthe format specifier “ %n” will give the number of characters actually formatted in the printf
function.
Int num = 10;
Char *a= “helloworld”;
Printf(“ %3x,%n ” ,num, &a);
Printf(“%d no of bytes are formatted here into hex”,a);
6. What's the difference between the following two C statements?
const char *p;
char* const p;
a) const char *p; p is a pointer to a constant character;
b) char* const p; p is a constant character pointer;
both are same.
7. How do you print I can print % using the printf function?
a) using %% in the format specifier.
Printf(“%d %% %d” ,a ,b);
Output is a % b;
8.
Bitwise Example:
if ((val==1)|(val==2)) printf("%d\n",val);
else printf("False");??
a)bitwise operators are operated on bits. for a bitwise OR operator, both of the left hand side and right hand side values/expressions are evaluated. then the 'evaluated values' are ORed together.
int a = 33, b = 40, c;
c = a | b;
/***********************
33 => 100001 a
40 => 101000 b
------------ OR
41 => 101001 c
***********************/
on the other hand, if expressions are used as the operands of bitwise operator OR:
int val = 2, a;
a = (val == 1) | (val == 2);
printf("%d\n", a);
then the output for the above code is always 1 if val is either 1 or 2, and the output is 0 otherwise. because, in the above case, (val == 1) is evaluated. if this is true, then (val==1) is considered 1, otherwise 0. similarly, (val == 2) is evaluated and is considered 1 or 0 depending if it is true or false. then these two 0 or 1 are ORed together.
logical operators work a little bit different way. say, the code is
(val==1) || (val==2)
the above is a logical expression, whose value is either true or false. to evaluate the above expression, first (val==1) is checked. if this is found true, then the entire expression become true and no further checking is required to check whether (val==2) or not, computer skips checking the right hand side, since they are ORed. if (val==1) is found false, then the value of the expression depends on whether (val==2) is true or false.
similarly, for logical AND operator,
(a==1) && (b==2)
first (a==1) is evaluated. if this is found false, then the entire expression become false and computer skips checking (b==2), since they are ANDed together. if (a==1) is found true, then the checking (b==2) is required to evaluate the whole expression.
so use logical operators when "if this AND that" or "if this OR that" kind of checking is required. go for the bitwise operator when u really need a new bit stream. remember, logical operators skip evaluating in certain conditions where bitwise operators always evaluate both sides.
Subscribe to:
Posts (Atom)